-
Notifications
You must be signed in to change notification settings - Fork 2
/
log-elk.html
129 lines (123 loc) · 5.04 KB
/
log-elk.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<script type="text/javascript">
RED.nodes.registerType('log-elk', {
category: 'output',
color: '#E9967A',
defaults: {
name: {
value: ""
},
logger: {value:"", type:"log-elk-logger"},
complete: {
value: "false",
required: true
},
loglevel: {
value: "debug",
required: true
}
},
inputs: 1,
outputs: 0,
icon: "file.svg",
align: "right",
label: function () {
return this.name || "log-elk";
},
oneditprepare: function () {
// message
$("#node-input-typed-complete").typedInput({
types: ['msg', {
value: "full",
label: RED._("node-red:debug.msgobj"),
hasValue: false
}]
});
if (this.complete === "true" || this.complete === true) {
// show complete message object
$("#node-input-typed-complete").typedInput('type', 'full');
} else {
var property = (!this.complete || (this.complete === "false")) ? "payload" : this.complete + "";
$("#node-input-typed-complete").typedInput('type', 'msg');
$("#node-input-typed-complete").typedInput('value', property);
}
$("#node-input-typed-complete").on('change', function () {
if ($("#node-input-typed-complete").typedInput('type') === 'msg' &&
$("#node-input-typed-complete").typedInput('value') === ''
) {
$("#node-input-typed-complete").typedInput('value', 'payload');
}
});
// loglevel
$("#node-input-typed-loglevel").typedInput({
types: [
'msg',
{
value:"level",
label:"level",
options:["error","warn", "info", "debug"]
}
]
});
if (this.loglevel === "error" ||
this.loglevel === "warn" ||
this.loglevel === "info" ||
this.loglevel === "debug") {
// fixed level
$("#node-input-typed-loglevel").typedInput('type', 'level');
$("#node-input-typed-loglevel").typedInput('value', this.loglevel);
} else {
$("#node-input-typed-loglevel").typedInput('type', 'msg');
$("#node-input-typed-loglevel").typedInput('value', this.loglevel);
}
$("#node-input-typed-loglevel").on('change', function () {
if ($("#node-input-typed-loglevel").typedInput('type') === 'msg' ) {
var value = $("#node-input-typed-loglevel").typedInput('value')
if (value === "error" || value === "warn" || value === "info" || value === "debug") {
$("#node-input-typed-loglevel").typedInput('value', 'loglevel');
}
}
});
},
oneditsave: function () {
var type = $("#node-input-typed-complete").typedInput('type');
if (type === 'full') {
$("#node-input-complete").val("true");
} else {
$("#node-input-complete").val($("#node-input-typed-complete").typedInput('value'));
}
$("#node-input-loglevel").val($("#node-input-typed-loglevel").typedInput('value'));
}
});
</script>
<script type="text/x-red" data-template-name="log-elk">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-logger"><i class="fa fa-random"></i> Logger</label>
<input type="text" id="node-input-logger" >
</div>
<div class="form-row">
<label for="node-input-typed-loglevel"><i class="fa fa-list"></i> Log Level</label>
<input id="node-input-typed-loglevel" type="text">
<input id="node-input-loglevel" type="hidden">
</div>
<div class="form-row">
<label for="node-input-typed-complete"><i class="fa fa-list"></i> Output</label>
<input id="node-input-typed-complete" type="text">
<input id="node-input-complete" type="hidden">
</div>
</script>
<script type="text/x-red" data-help-name="log-elk">
<p>A logging node with multiple log outputs using the winston, winston-elastic and winston-loki logging libraries</p>
<h3>Details</h3>
<p>Output <code>msg.payload</code> (or <code>msg.<custom path></code>) or complete <code>msg</code> is used as input of the logged message.
If it contains an Object it will be converted to a JSON string before being sent.</p>
<p>The Log Level (error, warn, info, debug) used can be configured in the node or can be set
by <code>msg.loglevel</code> (or <code>msg.<custom path></code>).
If the content is not one of ('error', 'warn', 'info', 'debug'), 'debug' will be used as fallback</p>
<p>If <code>msg.meta</code> is set, the meta info Object will be added to the output.</p>
<h3>References</h3>
<p>This node is based on parts of node-red-contrib-advance-logger</p>
</script>