Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (54 loc) · 1.59 KB
/
Copy pathindex.js
File metadata and controls
69 lines (54 loc) · 1.59 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
66
67
68
69
"use strict"
/**
* The `logger` is simple module enables to logging based on
* different LOG levels.
*
*
* ```js
* const LOG = require("Logger");
* ```
* import { LOG, WARN, ERROR } from 'Logger';
* ```
*
* OR
*
* ```
* import * as LOGGER from 'Logger';
* ```
* All file system operations have synchronous, callback, and promise-based
* forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
* @see [source](https://github.com/GTM-Software/fleet-dashboard.git)
*/
const fs = require("fs");
const LOGLEVEL = {
"INFO" : "INFO",
"WARN" : "WARN",
"ERROR" : "ERROR",
};
const properties = {
"logFileName" : "log",
"dateFormatString" : "",
"formatedDate" : new Date(),
};
const setLogFileName = (logFileName) => {
//TODO
}
const setDateFormat = (dateFormatString) => {
//TODO
}
const print = (LOGLEVEL, logMessage) => {
const logMsg = `[${LOGLEVEL}]:${properties.formatedDate}:${logMessage}\n`;
fs.mkdir('./logs', { recursive: true }, (err) => {
if (err) throw err;
});
const logFileName = `logs/${properties.logFileName}.log`;
fs.appendFile(logFileName, logMsg, (err, data) => {
if(err) {
throw console.error(`Error in Logging => ${err}`);
}
});
}
const INFO = (logMessage) => print(LOGLEVEL.INFO,logMessage);
const WARN = (logMessage) => print(LOGLEVEL.WARN,logMessage);
const ERROR = (logMessage) => print(LOGLEVEL.ERROR,logMessage);
module.exports = {INFO, WARN, ERROR, configureDateFormat: setDateFormat, configureLogFileName: setLogFileName, LOGLEVEL};