forked from timroemisch/mqtt-s7-connector
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice_functions.js
More file actions
65 lines (55 loc) · 1.45 KB
/
service_functions.js
File metadata and controls
65 lines (55 loc) · 1.45 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
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
// Log levels:
// 0: Trace
// 1: Debug
// 2: Info
// 3: Notice
// 4: Warning
// 5: Error > Exit program
// 6: Fatal > Exit program
function datetime() {
let ts = Date.now();
let date_time = new Date(ts);
let date = date_time.getDate();
let month = date_time.getMonth() + 1;
let year = date_time.getFullYear();
let hour = date_time.getHours();
let minute = date_time.getMinutes();
let second = date_time.getSeconds();
return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}
module.exports.trace = function trace(msg) {
if (global.log_level < 1) {
console.log(datetime() + " ## TRACE ## " + msg);
}
}
module.exports.debug = function debug(msg) {
if (global.log_level <= 1) {
console.log(datetime() + " ## DEBUG ## " + msg);
}
}
module.exports.info = function info(msg) {
if (global.log_level <= 2) {
console.log(datetime() + " ## INFO ## " + msg);
}
}
module.exports.notice = function notice(msg) {
if (global.log_level <= 3) {
console.log(datetime() + " ## NOTICE ## " + msg);
}
}
module.exports.warning = function warning(msg) {
if (global.log_level <= 4) {
console.log(datetime() + " ## WARNING ## " + msg);
}
}
module.exports.error = function error(msg) {
if (global.log_level <= 5) {
console.log(datetime() + " ## ERROR ## " + msg)
throw new Error(msg);
}
process.exit(-1);
}
module.exports.fatal = function fatal(msg) {
console.log(datetime() + " ## FATAL ## " + msg)
throw new Error(msg);
}