|
/* jslint node: true */ |
|
/* jshint esversion: 6 */ |
|
|
|
"use strict"; |
|
|
|
const { createLogger, format, transports, addColors } = require("winston"); |
|
const { combine, timestamp, label, prettyPrint } = format; |
|
|
|
var logger; |
|
|
|
const myCustomLevels = { |
|
levels: { |
|
error: 0, |
|
warn: 1, |
|
info: 2, |
|
foo: 3, |
|
}, |
|
// baz: 'italic yellow', |
|
// foobar: 'bold red cyanBG' |
|
|
|
// Possible options are below. |
|
|
|
// Font styles: bold, dim, italic, underline, inverse, hidden, strikethrough. |
|
|
|
// Font foreground colors: black, red, green, yellow, blue, magenta, cyan, white, gray, grey. |
|
|
|
// Background colors: blackBG, redBG, greenBG, yellowBG, blueBG magentaBG, cyanBG, whiteBG |
|
colors: { |
|
error: "red", |
|
warn: "yellow", |
|
info: "green", |
|
foo: "blue", |
|
}, |
|
}; |
|
|
|
const timezoned = () => { |
|
return new Date().toLocaleString("id-ID", { |
|
timeZone: "Asia/Kuala_Lumpur", |
|
}); |
|
}; |
|
|
|
logger = createLogger({ |
|
levels: myCustomLevels.levels, |
|
format: combine( |
|
// label({ label: 'right meow!' }), |
|
timestamp({ format: timezoned }), |
|
// format.splat(), |
|
prettyPrint(), |
|
|
|
// format.timestamp(), |
|
format.simple(), |
|
format.printf( |
|
(info) => `${info.timestamp} - ${info.level}: ${info.message}\r\n`, |
|
), |
|
format.colorize({ all: true }), |
|
format.json(), |
|
), |
|
transports: [ |
|
new transports.File({ filename: "error.log", level: "error" }), |
|
new transports.File({ filename: "combined.log" }), |
|
// new (transports.Console)({'timestamp':true}) |
|
new transports.Console({ |
|
format: format.combine(format.colorize(), format.simple()), |
|
}), |
|
], |
|
}); |
|
|
|
addColors(myCustomLevels.colors); |
|
|
|
module.exports = logger; |