μ½μ μΆλ ₯μ μμμ μ§μ νλ €κ³ νλλ° μλνμ§ μμ΅λλ€. μΆλ ₯μ λͺ¨λ λμΌν(ν°μ) μμμ λλ€. μ λ 3.0.0-rc1μ μμ΅λλ€.
const winston = require('winston');
const logLevels = {
levels: {
error: 0,
warn: 1,
info: 2,
http: 3,
sql: 4,
debug: 5
},
colors: {
error: "red",
warn: "darkred",
info: "black",
http: "green",
sql: "blue",
debug: "gray"
}
};
winston.addColors(logLevels);
const logger = winston.createLogger({...});
logger.add(new winston.transports.Console({colorize: true}));
λλ λν μ¬κΈ° μμ μ μμ μλνμ§λ§ μλνμ§ μμ΅λλ€.
logger.add(new winston.transports.Console({format: winston.format.combine(formatter, winston.format.colorize())}));
κ°μ¬ ν΄μ,
μλ°λ‘
logform μ€λͺ μλ₯Ό μ¬μ©νμ¬ λΆλΆμ μΌλ‘ μλνλλ‘ ν μ μμμ΅λλ€.
const alignedWithColorsAndTime = winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.align(),
winston.format.printf(info => `${info.timestamp} [${info.level}]: ${info.message}`),
);
JSON μΈμ λ€νμ μ²λ¦¬νλ λ°©λ²μ μ λͺ¨λ₯΄κ² μ΅λλ€.
const alignedWithColorsAndTime = winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.align(),
winston.format.printf((info) => {
const {
timestamp, level, message, ...args
} = info;
const ts = timestamp.slice(0, 19).replace('T', ' ');
return `${ts} [${level}]: ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ''}`;
}),
);
2μκ° νμ μμμ μλν μ μμμ΅λλ€. @Xeoncross κ°μ¬ν©λλ€!
winstonμ μμνκ³ μμμ΄ μλ μ½μλ μ»μμ΅λλ€...
λλ λ€μ μ μ‘ μ μ μ½λλ₯Ό μ¬μ©νκ³ μμμ΅λλ€.
new winston.transports.Console({
format: winston.format.simple()
})
μ΄ μ€λ λλ₯Ό μ½μ ν λ€μκ³Ό κ°μ΄ νμ΅λλ€.
new winston.transports.Console({
format: winston.format.combine(
winston.format.simple(),
winston.format.colorize()
)
})
κ·Έλ¦¬κ³ μ°¨μ΄κ° μμμ΅λλ€.
κ·Έλμ colorize νμμ μμΉλ₯Ό ββ1stλ‘ λ³κ²½νκ³ μμμ΄ μλνλλ‘ νμ΅λλ€.
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
})
@abrakadobr κ°μ¬ν©λλ€! κ·Έκ²μ νΈλ¦μ νλ€.
μ¬κΈ°μλ μ무 κ²λ ν¨κ³Όκ° μμκ³ μ¬μ ν μμμ΄ μμμΌλ©° colorizeλ₯Ό 맨 μλ‘ μ΄λνλ©΄ μ 보 νλκ° μΈμ½λ©λ λ¬Έμμ΄μ κΈ°λ‘νκ² λμμ΅λλ€.
κ°λ¨ν expressjs μ±μμ winston & morgan λ‘κΉ μ μ¬μ©νλ λ°©λ²μ 보μ¬μ£Όλ μμ§ λ₯Ό λ§λ€μμ΅λλ€.
@Xeoncross κ°μ¬ν©λλ€! λ΄ νμμ winston.format.colorize()λ₯Ό μΆκ°νλ©΄ ν¨κ³Όκ° μμμ΅λλ€. μ΄κ²μ΄ λ¬Έμμ μλ€λ κ²μ΄ ν₯λ―Έ λ‘μ΅λλ€. μλλ©΄ μ μ΄λ λ¬Έμμμ μ°Ύμ μ μμμ΅λλ€.
μλ‘μ΄ μ μ°μ±μ΄ λ§μμ λ€μ§λ§ λ λμ λ¬Έμλ₯Ό μ 곡νκΈ°λ₯Ό λ°λλλ€. λλ μ΄κ²μ μλμν€λ λ° λ무 μ€λ μκ°μ 보λλ€. winston.cli()
λ₯Ό μ¬μ©νλ μ°λ¦¬λ₯Ό μν νλ¬κ·Έ μ€ νλ μ΄ μλ @Xeoncrossμ μμ μ μ¬ν λ¨Ό κΈΈμ κ° κ²μ
λλ€.
νμ¬ λ¦΄λ¦¬μ€ λ²μ μΌλ‘ μννλ λ°©λ²μ μλ μ¬λμ΄ μμ΅λκΉ? λ¦΄λ¦¬μ€ ν보 λ²μ μ μ΅μ μ΄ μλλλ€.
μ½λλ₯Ό μ½μ λ μ 체 λ‘κ·Έλ₯Ό μμΉ νλ μ΅μ
μΌλ‘ all
λ₯Ό colorize
μ λ³΄λΌ μλ μμ΅λλ€.
colorize({ all: true })
@markhealey μ΄λ―Έ λ΄ package.jsonμμ winston μ’ μμ±μ μ κ±°ν λ€μ κ·νμ λ©μμ§λ₯Ό μ½μμ΅λλ€. κ°μ¬ν©λλ€ :+1:
Thx @Xeoncross. https://github.com/winstonjs/logform/blob/master/timestamp.js λ₯Ό μ΄ν΄λ³΄μμμ€. format
opt 맀κ°λ³μλ₯Ό μ¬μ©νμ¬ νμμ€ν¬ν νμμ μ§μ ν μ μμ΅λλ€. κ·Έλ¬λ μκ°λμμ£Όμνμμμ€
format.combine(
format.colorize(),
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.align(),
format.printf(info => {
const { timestamp, level, message, ...extra } = info;
return `${timestamp} [${level}]: ${message} ${
Object.keys(extra).length ? JSON.stringify(extra, null, 2) : ''
}`;
}),
)
format.colorize({all:true}
λ νμμ€ν¬νκ° ν¬ν¨λ κ²½μ° μ€μ λ‘ μλνμ§ μμ΅λλ€. λ€μμ μ 체 λΌμΈμ μμμ μ§μ νλ μμ
μμ
λλ€.
const colorizer = winston.format.colorize();
const logger = winston.createLogger({
level: 'debug',
format: combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg =>
colorizer.colorize(msg.level, `${msg.timestamp} - ${msg.level}: ${msg.message}`)
)
),
transports: [
new transports.Console(),
]
});
λ΄ μ 체 κΈ°λ₯ λ‘κ±° νμΈ
@abrakadobr μκ² κ°μ¬λ립λλ€. κ·νμ μ루μ μ΄ μ μκ² ν¨κ³Όμ μ΄μμ΅λλ€.
@tommuhm μ΄μ κ²°ν¨μ΄ 보μ
λλ€. printf
μ 체μ μμμ μ§μ νλ €λ κ²½μ° colorize
μ λν κΈ°λ³Έ μ 곡 νμ μ΅μ
μ΄ μμ΅λλ€. μ΄κ²μ΄ λΉμ μκ² μλ―Έκ° μμ΅λκΉ?
const { createLogger, format, transports } = require('../');
const logger = createLogger({
level: 'debug',
format: format.combine(
format.timestamp(),
format.simple(),
format.printf(info => `${info.timestamp} - ${info.level}: ${info.message}`),
format.colorize({ all: true })
),
transports: [
new transports.Console(),
]
});
logger.error('wowza');
κΉλ€λ‘μ΄ λΉνΈλ colorizer
info
κ° "μ§λ ¬ν"λμμ λ(μ¦, info[MESSAGE]
κ° λ¬Έμμ΄λ‘ μ€μ λμμ λ) colorizerλ₯Ό μ μ μλλ‘ νλ κ²μ
λλ€. 곧 logform
μ λν νμ PR β μμΈν μ΄ν΄μ£Όμ
μ κ°μ¬ν©λλ€!
@Xeoncross μ°λ¦¬λ ν¨μ¬ λ κ°λ¨ν λ°©λ²μΌλ‘ λμΌν κ²°κ³Όλ₯Ό μ»μ μλ μμ΅λλ€.
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, colorize, printf } = format;
const level = process.env.LOG_LEVEL || 'debug';
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} ${level}: ${message}`;
});
const logger = createLogger({
format: combine(colorize(), timestamp(), myFormat),
transports: [new transports.Console()]
});
μ°Έμ‘°: https://www.npmjs.com/package/winston#using -custom-logging-levels
λλ cloudwatchμ λ‘κ·ΈμΈνκΈ° μν΄ winstonμ μ¬μ©νκ³ μμμ μΆκ°νλ €κ³ νμ§λ§ μμ κΈ°νΈ λμ μ λνλ©λλ€. μμμ μΈκΈν λͺ¨λ μ루μ μ μλν©λλ€. μλλ λ΄ μ½λμ λλ€
const winston = require('winston');
const {transports, format, createLogger } = winston;
const { combine,errors,timestamp} = format;
const colorizer = winston.format.colorize();
const logger = createLogger({
level: process.env.LOG_LEVEL,
prettyPrint : true,
format: combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg =>
colorizer.colorize(msg.level, `${msg.timestamp} - ${msg.level}: ${msg.message}`)
)
),
transports: [
new transports.Console()
]
});
module.exports = {logger};
Cloudwatch μ½μ μΆλ ₯μμ
[34m2019-08-22T13:00:03.325Z - debug: res by id: [
{
"isActive": true,
"value": "fNUMheWiwXayKsaYCbUeA7Gg7BtEPIUbakB56XH1",
"id": "oehlwqlcve",
"userId": "6b347b41-ddef-4842-83a0-1cd5ca358482"
}
][39m
μ΄ [39m λ μμ λμ λνλ©λλ€. μ΄λ ν μ μ?
-22T13:00:03.325Z - λλ²κ·Έ: IDλ³ res: [
μ λ κ°μ λ¬Έμ κ° μμ΅λλ€. ν΄κ²°νμ ¨λμ?
-22T13:00:03.325Z - λλ²κ·Έ: IDλ³ res: [
μ λ κ°μ λ¬Έμ κ° μμ΅λλ€. ν΄κ²°νμ ¨λμ?
μ΄μ λν μ λ°μ΄νΈκ° μμ΅λκΉ? μ΄λ»κ²λ ν΄κ²°νμ ¨λμ?
@Xeoncross μ°λ¦¬λ ν¨μ¬ λ κ°λ¨ν λ°©λ²μΌλ‘ λμΌν κ²°κ³Όλ₯Ό μ»μ μλ μμ΅λλ€.
const { createLogger, format, transports } = require('winston'); const { combine, timestamp, colorize, printf } = format; const level = process.env.LOG_LEVEL || 'debug'; const myFormat = printf(({ level, message, label, timestamp }) => { return `${timestamp} ${level}: ${message}`; }); const logger = createLogger({ format: combine(colorize(), timestamp(), myFormat), transports: [new transports.Console()] });
μ°Έμ‘°: https://www.npmjs.com/package/winston#using -custom-logging-levels
κ·Έκ²μ MacOSμ iTermμμ λλ₯Ό μν΄ μμμλ₯Ό μΌμ΅λλ€.
μλ λ§ν¬κ° μ μκ² ν¨κ³Όμ μ΄μμ΅λλ€.
https://stackoverflow.com/questions/51012150/winston-3-0-colorize-whole-output-on-console
κ°μ₯ μ μ©ν λκΈ
logform μ€λͺ μλ₯Ό μ¬μ©νμ¬ λΆλΆμ μΌλ‘ μλνλλ‘ ν μ μμμ΅λλ€.
JSON μΈμ λ€νμ μ²λ¦¬νλ λ°©λ²μ μ λͺ¨λ₯΄κ² μ΅λλ€.
μ λ°μ΄νΈλ λ΄κ° ν΄κ²°ν κ²μ λλ€.