【问题标题】:Random error on winston-daily-rotate-file on azure app serviceazure 应用服务上的 winston-daily-rotate-file 随机错误
【发布时间】:2021-10-22 14:13:00
【问题描述】:

我正在使用 Node 14.15.1、winston 3.3.3 和 winston-daily-rotate-file 4.5.5 在 Azure 应用服务上运行

我在文件旋转时随机发现以下错误。

不确定我做错了什么以及如何解决这个问题。任何建议都非常感谢。

提前致谢,

错误

2021-10-20T00:00:44.445079522Z events.js:292
2021-10-20T00:00:44.445119022Z       throw er; // Unhandled 'error' event
2021-10-20T00:00:44.445125323Z       ^
2021-10-20T00:00:44.445129523Z 
2021-10-20T00:00:44.445134423Z Error: EIO: i/o error, close
2021-10-20T00:00:44.445137623Z Emitted 'error' event at:
2021-10-20T00:00:44.445140523Z     at WriteStream.<anonymous> (/node_modules/file-stream-rotator/FileStreamRotator.js:677:15)
2021-10-20T00:00:44.445143723Z     at WriteStream.emit (events.js:315:20)
2021-10-20T00:00:44.445146423Z     at emitErrorNT (internal/streams/destroy.js:106:8)
2021-10-20T00:00:44.445149223Z     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
2021-10-20T00:00:44.445153323Z     at processTicksAndRejections (internal/process/task_queues.js:80:21) {
2021-10-20T00:00:44.445157723Z   errno: -5,
2021-10-20T00:00:44.445162223Z   code: 'EIO',
2021-10-20T00:00:44.445166623Z   syscall: 'close'
2021-10-20T00:00:44.445170323Z 

日志记录代码

const logger = winston.createLogger({
    format: winston.format.combine(
        winston.format.splat(),
        winston.format.timestamp(),
        winston.format.printf(info => {
            return `${tsFormat()} | ${info.level} | ${ info.message }`;
        })
    ),
    transports: [
        new winston.transports.Console(),
        new winston.transports.DailyRotateFile({
            dirname: logDir,
            filename: '%DATE%-KBK.log',
            datePattern: 'YYYY-MM-DD',
            zippedArchive: true
        })
    ]
});

【问题讨论】:

    标签: node.js azure-web-app-service node-modules winston


    【解决方案1】:

    我正在关注这个blog。我没有遇到任何问题。

    对于日志记录,您可以使用以下代码的 sn-p

    const winston = require(“winston”);
    const DailyRotateFile = require(“winston-daily-rotate-file”);
    const config = require(“config”);
    const logFormat = winston.format.combine(
        winston.format.colorize(),
        winston.format.timestamp(),
        winston.format.align(),
        winston.format.printf(
        info => `${info.timestamp} ${info.level}: ${info.message}`,
    ),);
    
    const transport = new DailyRotateFile({
        filename: config.get(“logConfig.logFolder”) +  config.get(“logConfig.logFile”),
        datePattern: ‘YYYY-MM-DD-HH’,
        zippedArchive: true,
        maxSize: ‘20m’,
        maxFiles: ‘14d’,
        prepend: true,
        level: config.get(“logConfig.logLevel”),
    });
    
    transport.on(‘rotate’, function (oldFilename, newFilename) {
        // call function like upload to cloud
    });
    
    const logger = winston.createLogger({
        format: logFormat,
        transports: [
        transport,
        new winston.transports.Console({
        level: “info”,}),
    ]});
    module.exports = logger;
    

    您仍然面临这个问题,请尝试更改 Nodejs 的运行端口,EIO: i/o error, close 指出该端口正在被其他进程使用。

    【讨论】:

      猜你喜欢
      • 2016-06-30
      • 2019-06-12
      • 2019-10-21
      • 2017-01-31
      • 2020-09-28
      • 2022-01-20
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多