我正在尝试在我的 NodeJS 应用程序中使用 Winston 使用 Google 云日志记录。我正在试用 @google-cloud/logging-winston 软件包,并且能够成功登录到云端。
import winston from "winston";
import logging_winston from "@google-cloud/logging-winston";
const loggingWinston = new logging_winston.LoggingWinston({
level: 'info',
format: winston.format.json(),
logName: 'john-doe-log'
})
const logger = winston.createLogger({
level: "info",
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
defaultMeta: { service: 'user-service' },
transports: [
//new winston.transports.Console(),
loggingWinston
]
});
const message = {
user: "John Doe",
age: 29
}
const messageLogged = (data) => {
console.log("Message callback - ", data);
}
for(let i = 1; i <=100; i++) {
logger.info(`Hello World - ${i}`, message, messageLogged);
}
console.log("Done");
我想在登录到云时查看应用程序的性能。理想情况下,我想要一个“即发即忘”的异步调用,但是我看到程序结束大约有 1 - 2 秒的延迟。第一条和最后一条日志消息(使用循环)几乎相隔 2 秒。
如何在记录器中配置消息批处理并确保我的应用程序性能不受影响?
附言- 我是 NodeJS 的新手
更新 我用 Bunyan 尝试了同样的方法,它的性能要好得多。代码相同,首尾日志相差2ms。因此,这似乎与 Winston 的日志记录包如何将日志记录到云有关。