winston
๋ฒ์ ?_ 3.2.1winston@2
winston@3
node -v
์ถ๋ ฅ:_ v12.8.1Winston์ ์์ธ๋ฅผ ๊ธฐ๋กํ์ง ์๋ ๊ฒ ๊ฐ๊ณ ์ค๋ฅ ๊ฐ์ฒด๋ฅผ ์ ๋๋ก ๊ตฌ๋ฌธ ๋ถ์ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
transports: [
new winston.transports.File({
filename: `./logs/error-${momentLogger.unix()}.log`,
level: 'error'
}),
new winston.transports.File({
filename: `./logs/debug-${momentLogger.unix()}.log`,
level: 'debug'
}),
new winston.transports.File({
filename: `./logs/combined-${momentLogger.unix()}.log`
}),
new winston.transports.Console({
format: winston.format.simple()
})
]
});
try {
logger.debug(folderIdRegex.exec(event.link)[1]);
} catch (ex) {
console.log(ex); // Correctly prints
logger.info(ex); // Undefined
logger.debug(ex); // Undefined
logger.error(ex); // Undefined
}
VSCode ๋๋ฒ๊ฑฐ๋ฅผ ์ฌ์ฉํ ์ถ๊ฐ ๋๋ฒ๊น
// Output
TypeError: Cannot read property '1' of null
at .....google-sheets-scraping-testing.js:188:51
at processTicksAndRejections (internal/process/task_queues.js:85:5)
info: undefined {"timestamp":"2020-03-04T19:58:36.251Z"}
error: undefined {"timestamp":"2020-03-04T19:58:36.251Z"}
// Here I started using the built-in debug terminal
ex // Input into debug console
> TypeError: Cannot read property '1' of null // Result of ex
logger.log(ex) // Input into debug console
info: undefined {"timestamp":"2020-03-04T20:11:13.924Z"} // Result of logger.log(ex)
> DerivedLogger {_readableState: ReadableState, readable: true, _events: Object, _eventsCount: 3, _maxListeners: undefined, โฆ} // Result of logger.log(ex)
Winston์ด try...catch ๋ธ๋ก์์ catch๋ ์ค๋ฅ๋ฅผ ๊ธฐ๋กํ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค. ex.message
๋์ ex
๋ฅผ ์ ๋ฌํ๋ฉด ์ ๋๋ก ์ถ๋ ฅ๋ฉ๋๋ค. ex
๋ catch ๋ธ๋ก ์ ์ฒด์ ๊ฑธ์ณ ์ ์๋์ด ์์ง๋ง Winston์ ์ด๋ค ์ด์ ๋ก ์ด๋ฅผ ๊ตฌ๋ฌธ ๋ถ์ํ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ํ catch ๋ธ๋ก ๋ด์์ return ex
ํ๊ณ ๋ค๋ฅธ catch ๋ธ๋ก ๋ด์์ ๋ชจ๋ ๊ฒ์ ๋๋ฌ์ธ๋ฉด ์ ๋๋ก ์ถ๋ ฅ๋๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด ๋น์ ์์ ์ธ ๋์์ ๋ํ ์์ธํ ๋ด์ฉ์ ์ด๊ฒ์ด Winston์ ๋ฒ๊ทธ๋ผ๋ ๊ฒ์ ๊นจ๋ซ๊ธฐ ์ ์ ๋ด๊ฐ Discord์ ์์ฑํ ์ง์ ๊ฒ์๋ฌผ ์ ์์ง๋ฅผ ์ฐธ์กฐํ์ธ์ .
๋ํ ์ด ์ค๋ฅ๋ ๋ค๋ฅธ ์ฌ์ฉ์๊ฐ #1758์์ ์ง๋ ํ ๋ฌ ๋์ ๊ฒช์๋ ๋ฌธ์ ๋ ์๋ฐํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
๋๋ ์ด๊ฒ์ด ํ์์ ์ ์ฉํ ๋ winston ๋ก๊ฑฐ์ ์ ์ก ์ฌ์ด์ ์ผ๊ด์ฑ ์๋ ๋์ ๋๋ฌธ์ผ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. winston-transport์์ TransportStream _write ํจ์์ ์ผ๋ถ๋ ๋ค์์ ์ํํฉ๋๋ค.
transformed = this.format.transform(Object.assign({}, info), this.format.options);
winston/logger.js์ ๊ด๋ จ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
this.push(this.format.transform(info, this.format.options));
๋ค์์ ๋ฌธ์ ์ ๋จ์ํ๋ ์ฌํ์ ๋๋ค.
const winston = require('winston');
// First logger uses a format configured on logger
const logger1 = winston.createLogger({
level: 'info',
transports: new winston.transports.Console(),
format: winston.format.simple()
});
// Second logger uses a format configured on transport
const logger2 = winston.createLogger({
level: 'info',
transports: new winston.transports.Console({
format: winston.format.simple()
})
});
logger1.info(new Error('err message')); // logs expected 'err message'
logger2.info(new Error('err message')); // logs 'undefined'
์ด๋ค ํ๋์ ์ ํธํด์ผ ํ๋์ง ๋ช ํํ์ง ์์ต๋๋ค.
winston์ด ์ผ๋ถ ๊ฐ์ฒด๋ฅผ ์ ๋๋ก ๊ธฐ๋กํ์ง ์๊ณ [object Object]
์ธ์ํ๋ ๋ฐ๋ฉด ๋ค๋ฅธ ๊ฐ์ฒด๋ ๋ฌธ์ ์์ด ์ธ์ํ๋ ๊ฒฝ์ฐ์๋ ๋์ผํ ๊ฒฝ์ฐ์ธ์ง ๊ถ๊ธํฉ๋๋ค.
@jleverenz
๊ฐ์ฌํฉ๋๋ค, ์ข์ ๋ฐ๊ฒฌ! https://github.com/winstonjs/winston/issues/1758 ๊ณผ ๋์ผํ ๋ด ๋ฌธ์ ์ ๋ํ ๊ฐ๋จํ ํด๊ฒฐ ๋ฐฉ๋ฒ ์ ์ ๊ณตํ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ์ด๊ฒ์ด ํ์์ ์ ์ฉํ ๋ winston ๋ก๊ฑฐ์ ์ ์ก ์ฌ์ด์ ์ผ๊ด์ฑ ์๋ ๋์ ๋๋ฌธ์ผ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. winston-transport์์ TransportStream _write ํจ์์ ์ผ๋ถ๋ ๋ค์์ ์ํํฉ๋๋ค.
transformed = this.format.transform(Object.assign({}, info), this.format.options);
winston/logger.js์ ๊ด๋ จ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
this.push(this.format.transform(info, this.format.options));
๋ค์์ ๋ฌธ์ ์ ๋จ์ํ๋ ์ฌํ์ ๋๋ค.
์ด๋ค ํ๋์ ์ ํธํด์ผ ํ๋์ง ๋ช ํํ์ง ์์ต๋๋ค.