source: trip-planner-front/node_modules/log4js/lib/appenders/tcp-server.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1const debug = require('debug')('log4js:tcp-server');
2const net = require('net');
3const clustering = require('../clustering');
4const LoggingEvent = require('../LoggingEvent');
5
6const DELIMITER = '__LOG4JS__';
7
8exports.configure = (config) => {
9 debug('configure called with ', config);
10 // dummy shutdown if we're not master
11 let shutdown = (cb) => { cb(); };
12
13 clustering.onlyOnMaster(() => {
14 const server = net.createServer((socket) => {
15 let dataSoFar = '';
16 const send = (data) => {
17 if (data) {
18 dataSoFar += data;
19 if (dataSoFar.indexOf(DELIMITER)) {
20 const events = dataSoFar.split(DELIMITER);
21 if (!dataSoFar.endsWith(DELIMITER)) {
22 dataSoFar = events.pop();
23 } else {
24 dataSoFar = '';
25 }
26 events.filter(e => e.length).forEach((e) => {
27 clustering.send(LoggingEvent.deserialise(e));
28 });
29 }
30 }
31 };
32
33 socket.setEncoding('utf8');
34 socket.on('data', send);
35 socket.on('end', send);
36 });
37
38 server.listen(config.port || 5000, config.host || 'localhost', () => {
39 debug(`listening on ${config.host || 'localhost'}:${config.port || 5000}`);
40 server.unref();
41 });
42
43 shutdown = (cb) => {
44 debug('shutdown called.');
45 server.close(cb);
46 };
47 });
48
49 return {
50 shutdown
51 };
52};
Note: See TracBrowser for help on using the repository browser.