-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.js
More file actions
40 lines (36 loc) · 1.08 KB
/
logger.js
File metadata and controls
40 lines (36 loc) · 1.08 KB
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
/* logger.js -- application logger
* Copyright 2014 Sergei Ianovich
*
* Licensed under AGPL-3.0 or later, see LICENSE
* Process Control Service Web Interface
*/
var winston = require('winston'),
logger = null;
module.exports = {
enable: function(options) {
if (logger === null && options.transports) {
var transports = options.transports.map(function(item) {
item.options["handleExceptions"] = item.options["handleExceptions"] || true;
return new (winston.transports[item.name])(item.options);
});
logger = new (winston.Logger)({ transports: transports, exitOnError: false });
}
return logger;
},
logProcess: function(proc) {
if (proc) {
var messageHeader = null;
if (process.pid === proc.pid) {
messageHeader = "Master: ";
} else {
messageHeader = "Worker " + proc.pid + ": ";
}
proc.stdout.on('data', function(chunk) {
logger.info(messageHeader + chunk);
});
proc.stderr.on('data', function(chunk) {
logger.warn(messageHeader + chunk);
});
}
},
};