๋ฐ์ํ
winston ์ค์น ๋ฐ ์ค์
์๋ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํด์ ์ค์นํด์ค๋๋ค.
npm i winston
์ฝ๋ ์ค์
import winston from 'winston';
import dayjs from 'dayjs';
const messageSymbol = Symbol.for('message');
const colorset = {
"INFO": "\x1b[34m[ %s ]\x1b[0m",
"ERROR": "\x1b[31m[ %s ]\x1b[0m",
"WARN": "\x1b[33m[ %s ]\x1b[0m"
}
export async function init () {
winston.configure({
level: 'info',
format: winston.format.combine(
winston.format(function(info, opts) {
let prefix = util.format("[ %s ]", dayjs().format('YYYY.MM.DD HH:mm:ss A'));
let level = util.format(colorset[info.level.toUpperCase()], info.level.toUpperCase());
info.message = util.format('\x1b[36m%s\x1b[0m %s %s ', prefix, level, info.message);
return info;
})(),
winston.format(function(info) {
info[messageSymbol] = info.message;
return info;
})()
),
transports: [
new (winston.transports.Console)({
level: 'debug',
colorize: true,
prettyPrint: true
})
]
});
}
์ฝ์ ์์ํ
์์์ ์ฐ์ธ ์์ํ๋ ์๋๋ฅผ ์ฐธ๊ณ ํ๋ฉด ๋ฉ๋๋ค.
๋ฏธ๋ฆฌ ๋ณด๊ธฐ
๊ทธ๋ผ ๋ค์๊ณผ ๊ฐ์ด ์์์ด ์ ์ฉ๋๋ ๋ชจ์ต์ ํ์ธํ ์ ์์ต๋๋ค.
๋ฐ์ํ
'๐ป๊ธฐ์ > NodeJS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ NodeJS ] Webpack + SASS ์ค์ ํ๊ธฐ (0) | 2022.07.11 |
---|---|
[ ES6 ] webpack 5 ์๋ฐ์คํฌ๋ฆฝํธ ๋๋ ํ (0) | 2022.03.22 |
[ NodeJS ] Express์์ ๋ค์ค ๋ผ์ฐํฐ ์ฌ์ฉํ๊ธฐ (0) | 2022.01.02 |
[ ์ฝ๋๋ณด๋ฉฐ ๋ฐฐ์ฐ๋ NodeJS ] EJS ์ด๊ธฐ ์ฝ๋ (0) | 2020.03.30 |
[ ์ฝ๋๋ณด๋ฉฐ ๋ฐฐ์ฐ๋ NodeJS ] ์ด๊ธฐ ์ฝ๋ ์ธํ (0) | 2020.03.17 |