-
Notifications
You must be signed in to change notification settings - Fork 2
/
log-elk.js
41 lines (33 loc) · 1.13 KB
/
log-elk.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
module.exports = function (RED) {
"use strict";
function LogElkNode(config) {
RED.nodes.createNode(this, config);
const node = this;
this.logger = RED.nodes.getNode(config.logger);
var complete = config.complete;
var loglevel = config.loglevel || "debug";
this.on('input', function(msg, send, done) {
if (node.logger)
{
var level;
if (loglevel === "error" || loglevel === "warn" || loglevel === "info" || loglevel === "debug") {
// fixed level
level = loglevel;
} else {
// get loglevel from message
try { level = RED.util.getMessageProperty(msg, loglevel); }
catch(err) {
level = "debug";
}
if (!(level === "error" || level === "warn" || level === "info" || level === "debug")) {
// invalid log level, default to debug
level = "debug";
}
}
node.logger.addToLog(level, msg, complete);
}
if (done) done();
});
}
RED.nodes.registerType("log-elk", LogElkNode);
};