【发布时间】:2020-07-14 00:51:56
【问题描述】:
您是否知道如何使用 shimmer(https://www.npmjs.com/package/shimmer) 对节点 js winston 日志记录方法(如 info、调试)进行猴子修补?
例如, 这是我的 winston 3.x 设置:
let winston = require('winston')
winstonInit = winston.createLogger({
format: winston.format.json(),
transports: [
new winston.transports.Console({ level: 'info' }),
new winston.transports.File({
name: 'winston-logging',
level: 'info',
filename: './log/winston.log',
handleExceptions: true
})
],
exceptionHandlers: [
new winston.transports.File({ filename: './log/exceptions.log', handleExceptions: true})
]
});
winston.add(winstonInit);
所以,在我的应用程序中,我可以调用它
winston.info('send this message to Slack') // output: send this message to Slack .除了显示消息,我们还执行了其他功能。
我只想对这个 winston.info() 进行修补,例如添加一些额外的功能,例如在执行 winston.info 时发送 Slack 消息通知。谢谢。
【问题讨论】:
-
你目前是如何配置
winston的? -
@DhruvShah 我已在摘要中添加了我的 winston 设置。
-
你可以在winston中使用http传输来发送任何webpoint。