-
Notifications
You must be signed in to change notification settings - Fork 0
/
hydra-logging-svcs.js
64 lines (58 loc) · 1.67 KB
/
hydra-logging-svcs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @name HLS Service
* @summary User Hydra service entry point
* @description Hydra Logging Service
*/
const url = require('url');
const http = require('http');
const hydra = require('hydra');
const ServerResponse = hydra.getServerResponseHelper();
let serverResponse = new ServerResponse();
const Logger = require('./lib/logger');
/**
* @name main
* @description Load configuration file and initialize hydra app
* @return {undefined}
*/
let main = async () => {
try {
let config = await hydra.init(`${__dirname}/config/config.json`, false);
let serviceInfo = await hydra.registerService();
let logEntry = `Starting service ${serviceInfo.serviceName}:${hydra.getInstanceVersion()} on ${serviceInfo.serviceIP}:${serviceInfo.servicePort}`;
console.log(logEntry);
let server = http.createServer((req, res) => {
let urlData = url.parse(req.url);
if (urlData.path === '/v1/hls/health') {
let healthInfo = hydra.getHealth();
serverResponse.sendOk(res, {
result: healthInfo
});
} else {
serverResponse.sendNotFound(res, {
});
}
});
server.listen(serviceInfo.servicePort);
await hydra.registerRoutes([
'[get]/v1/hls/health'
]);
let logger = new Logger();
logger.init(config.logger);
logger.process({
bdy: {
serviceName: serviceInfo.serviceName,
serviceVersion: hydra.getInstanceVersion(),
instanceID: hydra.getInstanceID(),
severity: 'info',
bdy: logEntry
}
});
hydra.on('message', (msg) => {
logger.process(msg);
});
} catch (err) {
console.log('err', err);
process.exit(1);
}
};
main();