forked from x821938/node-red-contrib-flogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flogger.html
258 lines (239 loc) · 10.5 KB
/
flogger.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<script type="text/javascript">
RED.nodes.registerType('config-log',{
category: 'config',
defaults: {
logname: {value:"",required:true},
logdir: {value:"",required:true},
stamp: {value:"utc"},
logstyle: {value:"plain"},
logrotate: {value:""},
logcompress: {value:""},
logrotatecount: {value: "5"},
logsize: {value: "1000"}
},
label: function() {
return this.logname
},
oneditprepare: function() {
$("#node-config-input-logrotate").change(function() {
if ($(this).is(':checked')) {
$("#node-config-rotate-row").show()
} else {
$("#node-config-rotate-row").hide()
}
})
},
oneditsave: function() {
if ($("#node-config-input-logrotate").is(':checked')) {
if ($("#node-config-input-logrotatecount").val() < 1) $("#node-config-input-logrotatecount").val(5)
if ($("#node-config-input-logsize").val() < 1) $("#node-config-input-logsize").val(1000)
}
}
})
</script>
<script type="text/x-red" data-template-name="config-log">
<div class="form-row">
<label for="node-config-input-logname"><i class="icon-bookmark"></i> Config Name</label>
<input type="text" id="node-config-input-logname">
</div>
<div class="form-row">
<label for="node-config-input-logdir"><i class="fa fa-sitemap"></i> Log Dir</label>
<input type="text" id="node-config-input-logdir">
</div>
<div class="form-row">
<label for="node-config-input-stamp"><i class="fa fa-clock-o"></i> Timestamp</label>
<select type="text" id="node-config-input-stamp" placeholder="Time Stamp">
<option value="none">None</option>
<option value="utc">UTC</option>
<option value="local">Local</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-logstyle"><i class="fa fa-clock-o"></i> Log Style</label>
<select type="text" id="node-config-input-logstyle" placeholder="Log Style">
<option value="plain">Plain Text</option>
<option value="json">Pure JSON</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-logrotate"><i class="fa fa-repeat"></i> Rotate</label>
<input type="checkbox" id="node-config-input-logrotate" style="display: inline-block; width: auto; vertical-align: top;">
</div>
<div id="node-config-rotate-row">
<div class="form-row">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-logcompress"><i class="fa fa-compress"></i> Compress</label>
<input type="checkbox" id="node-config-input-logcompress" style="display: inline-block; width: auto; vertical-align: top;">
</div>
<div class="form-row">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-logrotatecount"><i class="fa fa-hashtag"></i> Max logfiles</label>
<input type="text" id="node-config-input-logrotatecount" style="display: inline-block; width: 50%; vertical-align: top;">
</div>
<div class="form-row">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-logsize"><i class="fa fa-hashtag"></i> Max size /kB</label>
<input type="text" id="node-config-input-logsize" style="display: inline-block; width: 50%; vertical-align: top;">
</div>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('flogger',{
category: 'output',
color: '#FFAAAA',
icon: "file.png",
defaults: {
name: {value:""},
logfile: {value:""},
heading: {value:"", required: true},
inputchoice: {value:"fullmsg"},
inputobject: {value:"payload"},
inputobjectType: {value: 'msg'},
inputmoustache: {value: 'Recieved payload {{payload}} and topic {{topic}}'},
loglevel: {value:"INFO", required: true},
logconfig: {type:"config-log"},
sendpane: {value:""},
},
inputs:1,
outputs:1,
label: function() {
return this.name||"flogger"
},
oneditprepare: function() {
$('#node-input-inputobject').typedInput({
default: 'msg',
typeField: $("#node-input-inputobjectType"),
types: ['msg','flow','global']
})
$("#node-input-inputchoice").change(function() {
if ($(this).val() == "fullmsg") {
$(".inputobject").hide()
$(".inputmoustache").hide()
}
if ($(this).val() == "object") {
$(".inputobject").show()
$(".inputmoustache").hide()
}
if ($(this).val() == "moustache") {
$(".inputobject").hide()
$(".inputmoustache").show()
}
})
}
})
</script>
<script type="text/x-red" data-template-name="flogger">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-logfile"><i class="fa fa-file-text-o"></i> Logfile</label>
<input type="text" id="node-input-logfile" placeholder="Name of the logfile">
</div>
<div class="form-row">
<label for="node-input-heading"><i class="fa fa-fa-header"></i> Prefix</label>
<input type="text" id="node-input-heading" placeholder="Prefix to add to the log">
</div>
<div class="form-row">
<label for="node-input-inputchoice"><i class="fa fa-exclamation"></i> Log</label>
<select type="text" id="node-input-inputchoice" placeholder="">
<option value="fullmsg">Full Message object</option>
<option value="object">Select object</option>
<option value="moustache">Moustache formatting</option>
</select>
</div>
<div class="form-row inputmoustache">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-inputobject"><i class="fa fa-chevron-right"></i> Moustache</label>
<textarea id="node-input-inputmoustache" rows="5" style="width:70%"></textarea>
</div>
<div class="form-row inputobject">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-inputobject"><i class="fa fa-chevron-right"></i> Object</label>
<input type="text" id="node-input-inputobject" style="width:70%">
<input type="hidden" id="node-input-inputobjectType">
</div>
<div class="form-row">
<label for="node-input-loglevel"><i class="fa fa-exclamation"></i> Level</label>
<select type="text" id="node-input-loglevel" placeholder="Log Level">
<option value="ERROR">ERROR</option>
<option value="WARN">WARN</option>
<option value="INFO">INFO</option>
<option value="DEBUG">DEBUG</option>
<option value="TRACE">TRACE</option>
</select>
</div>
<div class="form-row">
<label for="node-input-logconfig"><i class="fa fa-cogs"></i> Log Config</label>
<input type="text" id="node-input-logconfig" placeholder="Log Configuration">
</div>
<div class="form-row">
<label for="node-input-sendpane"><i class="fa fa-bug"></i> Add To Pane</label>
<input type="checkbox" id="node-input-sendpane" style="display: inline-block; width: auto; vertical-align: top;">
</div>
</script>
<script type="text/x-red" data-help-name="flogger">
<p>Advanced logger for outputting to multiple files</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>msg
<span class="property-type">object</span>
</dt>
<dd> Whatever object is sent into flogger will be sent to a file. </dd>
<dt>msg.loglevel
<span class="property-type">string</span>
</dt>
<dd> This can be used to override the loglevel set on the node. Possible
values: ERROR, WARN, INFO, DEBUG and TRACE. If an invalid level is provided
the node will default to the loglevel set on the node </dd>
<dt>msg.logfile
<span class="property-type">string</span>
</dt>
<dd> This can be used to override the name of the logfile set on the node.
If not provided flogger will log to the name provided in the node config.
</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>msg
<span class="property-type">object</span>
</dt>
<dd> If you chose to use flogger for passthrough to another node, the incoming
msg object will be send out without modification </dd>
</dl>
<h3>Details</h3>
<p>Any msg object can be sent into flogger and it will be written to a logfile.
<h3>Log Config</h3>To setup flogger
you first have to create a config. Most users will only have 1 config entry.</p>
<p>In the config you define <code>Log Dir</code> which describes the log directory relative to ~.
Eg. writing "logs" in this field will place logfiles under /home/username/logs on linux. Remember
that you have to create the directory yourself</p>
<p>In the <code>Timestamp</code> dropdown you can choose if you want to stamp each log line with
either UTC time, local time or no time at all</p>
<p>In the <code>Log Style</code> dropdown you can choose if you want a normal plain logfile similar
to syslog, or if you want a json logfile similar to NLOG</p>
<p>Check <code>Rotate</code> If you want to do automatic log rotation. If checked 3 more options
are shown:</p>
<p><code>Compress</code> Each rotated logfile will be gzip compressed if checked</p>
<p><code>Max logfiles</code> defines how many of each logfile you want. When the rotation
ends up with more than this amount the oldest will be deleted</p>
<p><code>Max Size /kB</code></p> defines the maximum allowed file size per logfile in kilobytes.
When this is reached the file is rotated.
<h3>Node setup</h3>
<p><code>Logfile</code> is the filename that the current node will log to. It can be overridden
with msg.logfile. If nothing is provided in this field and it's not overridden you will get an
error shown on the node</p>
<code>Log</code> is a selection what to log. If you select "Full Message Object", the entire msg object
will be logged. If you choose "Select Object" you can log part of a message eg. msg.payload. You can also log
flow and global variables. The third option (Moustache formatting) is to create your own template for a logmessage.
If you choose this you will get an example template that should work out of the box. Modify it to your own needs.</p>
<p><code>Level</code> can be set to ERROR, WARM, INFO, DEBUG or TRACE</p>
<p><code>Add to Pane</code> can be checked if you also want the message sent to the debug side pane
of Node-RED.</p>
<h3>Operation</h3>
<p>Whenever flogger receives a message the status text on the node will change to the time it
received the message. If the file can´t be written an error message will be displayed on the
node. Most obvious cause could be that the ouput directory doesn't exist or doesn't have the
right permissions</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/x821938/node-red-contrib-flogger.git">Github repository</a> - Full Source code</li>
<li><a href="https://cron.dk">Cron.dk</a> - My personal blog</li>
</ul>
</script>