winston
λ²μ ? _winston@2
winston@3
node -v
μΆλ ₯ : v10.1.0κΈ°λ³Έ μ 곡 μ½μ μ μ‘μ μ¬μ©νλ©΄ μ μμ μΌλ‘ μ€νλ λ (μ : node ./dist/index.js
) μ½μμ κΈ°λ‘λμ§λ§ Visual Studio Codeμμ λλ²κΉ
ν λλ λλ²κ·Έ μ½μμ κΈ°λ‘λμ§ μμ΅λλ€. console.log () / warn () / error ()μ λν νμ€ νΈμΆμ λλ²κ·Έ μ½μμ κΈ°λ‘λ©λλ€.
λͺ¨λ λ©μμ§κ° μ μμ μΌλ‘ μ€νλ λ νμ€ μ½μμ κΈ°λ‘λλ κ²μ²λΌ λλ²κ·Έ μ½μμ κΈ°λ‘ λ κ²μΌλ‘ μμν©λλ€.
λ¬Έμ λ μ μ‘ κ΅¬νμ log () λ©μλμμ _stderr.write () λ° _stdout.write ()λ₯Ό μ¬μ©νλ κ² κ°μ΅λλ€. νμ€ console.log () / warn () / error () ν¨μκ° νΈμΆλλλ‘ 49, 62 λ° 77μ if λ¬Έμ 쑰건μ false
λ°κΎΈλ©΄ μΆλ ₯μ΄ μ½μ μΆλ ₯μ λλ¬ν©λλ€. . λΆλͺ
ν λ°λμ§νμ§ μμ λΆμμ©μ 컀μ€ν
eolμ΄ λ¬΄μλλ€λ κ²μ
λλ€.
λ λ§μ vscode λ²κ·Έμ²λΌ λκ»΄μ§λλ€-μ°λ¦¬κ° κ·Έλ κ² μ±κ³΅μ μΌλ‘ μΈ μ μλ€λ©΄ μ κ·Έλ€μ λλ²κ·Έ μ½μμ _stdout
μ κ°μ μνμ΄ μμ΅λκΉ? λ¬Όλ‘ , vscodeμ λν΄ μλνλ ν΄κ²° λ°©λ²κ³Ό κ°μ μμ λ μ μ‘μ κ°μ§ μ μμ§λ§ μ΄μμ μ΄μ§ μμ μ μμ΅λλ€. μ΄κ²μ΄ winstonμμ μμ λμ΄μΌνλ€κ³ μκ°νλ κ²½μ° μ΄λ€ μμ΄λμ΄λ μμ λ‘κ² μ 곡 ν μ μμ΅λλ€. :)νμ§λ§ winstonμ΄ vscodeμμ μ€ν μ€μΈμ§ νμΈν΄μΌνλ€κ³ μκ°νμ§ μμ΅λλ€. μ€νλ € vscodeμ μ½μμ΄ λ μ μλν΄μΌνλ κ² κ°μ΅λλ€.
μ΄ λ¬Έμ λ₯Ό ν΄κ²°ν΄μΌνμ§λ§ λ λ§μ μ‘°μ¬κ° νμν©λλ€.
λ°©κΈμ΄ λ¬Έμ κ° λ°μνμ¬ μμ£Ό κ°λ¨ν μμ΄λμ΄λ₯Ό μΆκ°νκ³ μΆμμ΅λλ€. console.log
, console.warn
λ° console.error
π
νμ¬ Winstonμ [console._stderr] λ° [console._stdout]μ νμΈνκ³ μμΌλ©° μ΄λ¬ν μ€νΈλ¦Όμ μ§μ μ°λ κ²μ μ νΈνμ§λ§ console.warn
, console.error
λ° console.log
μ¬μ©μ μ νΈν©λλ€. μ¬μ©ν μμλ κ²½μ° _stderr
λ° _stdout
)μ node.jsμ μ μ μ½μ μΈμ€ν΄μ€μμ μ¬μ©ν μ μμ§λ§ [console] APIμ μΌλΆλ‘ λ¬Έμνλμ΄ μμ§ μμΌλ©° μ΄κ±° ν μλ μμ΅λλ€.
λ©μλλ₯Ό νΈμΆνλ κ²λ³΄λ€ Winstonμμ μ§μ μ€νΈλ¦Όμ μ¬μ©νλ κ²μ μ₯μ μ 무μμ
λκΉ? λλ₯Ό μν΄, console
μλ° μ€ν¬λ¦½νΈ 컨ν
μ€νΈ μλ¨μ ꡬ체μ μΌλ‘ console
κ°μ²΄, μΌλ°μ μΌλ‘ λλ μ€νΈλ¦Όμ λν νλ‘μλ‘νμ§ "μ½μ". λ°©λ²μ΄ νμ μλνμ§ μμ΅λκΉ? νΉν Winstonμ λ΄μ₯ λ stream
μ μ‘μ΄ μκΈ° λλ¬Έμ "μ½μ"μ κΈ°λ³Έμ μΌλ‘ λ‘컬 κ°λ°μ μ ν©νλ€κ³ ν΄μν©λλ€.
VS Codeλ ν΄λΉ μμ± (μλ§λ λ
Έλμμ μ€ν μ€μ΄κΈ° λλ¬Έμ)μ _have_νμ§λ§ λλ²κ·Έ μ½μμ κΈ°λ³Έ "capture"λ "console"μ
λλ€. μ΄λ μλ§λ console.log
νΈμΆμ νΉλ³ν νν¬λ₯Ό μ€μΉνμμ μλ―Έν©λλ€. , μ€νΈλ¦Ό μμ²΄κ° μλλλ€. μ¦ VS Codeκ° μΆλ ₯μ μμ±νμ§λ§ μΊ‘μ²νμ§λ μμ΅λλ€. μ΄ νμΌ κ³Ό κ΄λ ¨
λ€λ₯Έ μ¬λλ€μ΄ μΈκΈνλ―μ΄, μ΄λ€ μΆλ ₯ VS Code μΊ‘μ²λ₯Ό λ³κ²½νκ±°λ Winstonμμ "μ½μ"μ μ‘μ΄ μννλ μμ μ λ³κ²½ν μ μμ΅λλ€.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/index.js",
// Capture "std" instead of "console"
"outputCapture": "std"
}
]
}
@ adi7ya μ λ§ν¬ λ μ‘°μΈμ λ°λ₯΄λ©΄ VS Codeλ console.log
κ° νΈμΆ λ μ€μ μΆλ ₯ν©λλ€.μ΄ μ€μ Winstonμ νΈμΆ ν κ³³μ΄ μλλΌ μ¬μ μ λ log
μ
λλ€. λ°λΌμ μ½κ°λ§ μ μ© ν μ μμ΅λλ€.
VS Code μ¬λλ€κ³Ό ν¨κ» μ½μ μ μ‘ μΆλ ₯μ νμν vsc μ€μ μ ν μ μλμ§ νμΈνμ¬ κΈ°λ³Έκ°μ μΊ‘μ²ν©λλ€ : https://github.com/Microsoft/vscode/issues/69959 . κ·Έλ μ§ μμΌλ©΄ νμν vsc μ€μ λ³κ²½μ΄ λ΄ μ견μμ λ§ν¬λ©λλ€. ^^νμ§λ§ μ½μ μ μ‘μ λν μ ν¨ν μ§λ¬Έμ λλ€. μΈκΈ°μλ λ§μ νΈμ§μκ° κΈ°λ³Έμ μΌλ‘ "μ¬λ°λ₯Έ"μμ μ μννμ§ μμΌλ©΄ μ½μ μ μ‘ cc @indexzero μ λμμ λ³κ²½ν΄μΌν©λλ€.
μ΄κ²μ λν λλ₯Ό λ¬Όμκ³ @victorandreeμ λ λ§μ΄ λμ ν μ μμμ΅λλ€.
λ€λ₯Έ μ¬λμ΄ μ μ©νλ€κ³ μκ°νλ κ²½μ° νμ¬ λ΄ λͺ©μ μ μν΄ λ§€μ° λ² μ΄ λ³Έ μ μ‘μ μ¬μ©νκ³ μμ΅λλ€.
import winston from "winston";
import Transport from "winston-transport";
const { MESSAGE } = require("triple-beam");
const level = process.env.LOG_LEVEL || "info";
class SimpleConsoleTransport extends Transport {
log = (info: any, callback: any) => {
setImmediate(() => this.emit("logged", info));
console.log(info[MESSAGE]);
if (callback) {
callback();
}
};
}
export const logger = winston.createLogger({
level,
defaultMeta: {},
transports: [new SimpleConsoleTransport()]
});
# 1836μμμ΄ λ¬Έμ λ₯Ό ν΄κ²°νλ λ΄ μ μμ νμΈνμμμ€.
λνμ΄ λ¬Έμ κ° λ°μνμΌλ©° VSCodeμ κ΄λ ¨λ κ²μΌλ‘ 보μ΄μ§ μμ΅λλ€. node --inspect
λ₯Ό μ€ν ν λ€μ chrome://inspect
Chromeμμ μ°κ²°νλ©΄ console.log/etc
νΈμΆ λ§ νμλ©λλ€
κ°μ₯ μ μ©ν λκΈ
λ°©κΈμ΄ λ¬Έμ κ° λ°μνμ¬ μμ£Ό κ°λ¨ν μμ΄λμ΄λ₯Ό μΆκ°νκ³ μΆμμ΅λλ€.
console.log
,console.warn
λ°console.error
πνμ¬ Winstonμ [console._stderr] λ° [console._stdout]μ νμΈνκ³ μμΌλ©° μ΄λ¬ν μ€νΈλ¦Όμ μ§μ μ°λ κ²μ μ νΈνμ§λ§
console.warn
,console.error
λ°console.log
μ¬μ©μ μ νΈν©λλ€. μ¬μ©ν μμλ κ²½μ°_stderr
λ°_stdout
)μ node.jsμ μ μ μ½μ μΈμ€ν΄μ€μμ μ¬μ©ν μ μμ§λ§ [console] APIμ μΌλΆλ‘ λ¬Έμνλμ΄ μμ§ μμΌλ©° μ΄κ±° ν μλ μμ΅λλ€.λ©μλλ₯Ό νΈμΆνλ κ²λ³΄λ€ Winstonμμ μ§μ μ€νΈλ¦Όμ μ¬μ©νλ κ²μ μ₯μ μ 무μμ λκΉ? λλ₯Ό μν΄,
console
μλ° μ€ν¬λ¦½νΈ 컨ν μ€νΈ μλ¨μ ꡬ체μ μΌλ‘console
κ°μ²΄, μΌλ°μ μΌλ‘ λλ μ€νΈλ¦Όμ λν νλ‘μλ‘νμ§ "μ½μ". λ°©λ²μ΄ νμ μλνμ§ μμ΅λκΉ? νΉν Winstonμ λ΄μ₯ λstream
μ μ‘μ΄ μκΈ° λλ¬Έμ "μ½μ"μ κΈ°λ³Έμ μΌλ‘ λ‘컬 κ°λ°μ μ ν©νλ€κ³ ν΄μν©λλ€.VS Codeλ ν΄λΉ μμ± (μλ§λ λ Έλμμ μ€ν μ€μ΄κΈ° λλ¬Έμ)μ _have_νμ§λ§ λλ²κ·Έ μ½μμ κΈ°λ³Έ "capture"λ "console"μ λλ€. μ΄λ μλ§λ
console.log
νΈμΆμ νΉλ³ν νν¬λ₯Ό μ€μΉνμμ μλ―Έν©λλ€. , μ€νΈλ¦Ό μμ²΄κ° μλλλ€. μ¦ VS Codeκ° μΆλ ₯μ μμ±νμ§λ§ μΊ‘μ²νμ§λ μμ΅λλ€. μ΄ νμΌ κ³Ό κ΄λ ¨λ€λ₯Έ μ¬λλ€μ΄ μΈκΈνλ―μ΄, μ΄λ€ μΆλ ₯ VS Code μΊ‘μ²λ₯Ό λ³κ²½νκ±°λ Winstonμμ "μ½μ"μ μ‘μ΄ μννλ μμ μ λ³κ²½ν μ μμ΅λλ€.
@ adi7ya μ λ§ν¬ λ μ‘°μΈμ λ°λ₯΄λ©΄ VS Codeλ
console.log
κ° νΈμΆ λ μ€μ μΆλ ₯ν©λλ€.μ΄ μ€μ Winstonμ νΈμΆ ν κ³³μ΄ μλλΌ μ¬μ μ λlog
μ λλ€. λ°λΌμ μ½κ°λ§ μ μ© ν μ μμ΅λλ€.