-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
49 lines (48 loc) · 1.75 KB
/
logger.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
42
43
44
45
46
47
48
49
const winston = require("winston")
require("winston-daily-rotate-file")
const path = require('path')
const APP_NAME = process.env.APP_NAME || 'parental-control'
const LOG_DIR = path.join(process.env.ROOT_FOLDER || '.','/logs')
const LOG_LEVEL_CONSOLE = process.env.LOG_LEVEL_CONSOLE || 'error'
const LOG_LEVEL_FILE = process.env.LOG_LEVEL_FILE || 'info'
/*****************************************************************/
/******************* Logger ***************/
/*****************************************************************/
var transportFile = new winston.transports.DailyRotateFile({
dirname: LOG_DIR,
filename: `${APP_NAME}-%DATE%.log`,
datePattern: "YYYY-MM-DD",
zippedArchive: true,
maxSize: "10m",
maxFiles: "14d",
zippedArchive: true,
level: LOG_LEVEL_FILE,
format: winston.format.combine(
winston.format.timestamp(),
// winston.format.json()
winston.format.simple()
),
});
var transportConsole = new winston.transports.Console({
level: LOG_LEVEL_CONSOLE,
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple(),
winston.format.timestamp()
),
});
var logger = winston.createLogger({
transports: [transportConsole, transportFile],
});
// Samples
// logger.log('debug', "127.0.0.1 - there's no place like home");
// logger.log('verbose', "127.0.0.1 - there's no place like home");
// logger.log('info', "127.0.0.1 - there's no place like home");
// logger.log('warn', "127.0.0.1 - there's no place like home");
// logger.log('error', "127.0.0.1 - there's no place like home");
// logger.info("127.0.0.1 - there's no place like home");
// logger.warn("127.0.0.1 - there's no place like home");
// logger.error("127.0.0.1 - there's no place like home");
module.exports = {
logger
}