首页 > 解决方案 > Winston Logger (v2.4) 即使在旋转后也写入文件

问题描述

我有一个用于控制台输出的传输器以及一个用于文件输出的传输器。这工作正常并创建一个新的日志文件,同时重命名旧的,例如。日志/appLogs.txt 和日志/appLogs1.txt

我面临的问题是它继续写入第一个文件,即使它高于最大大小。Winston 正在记录到这两个文件,但在两者之间拆分日志。

例如:appLogs1.txt 2019-02-21T18:53:04.581Z - debug: ... logs

和 appLogs.txt 2019-02-21T18:53:04.538Z - debug: ... logs

我可以 ssh 进入容器并ls -l看到两个文件都在增长。

下面是我的温斯顿配置:

new winston.Logger({
            transports: [
                new winston.transports.Console({
                    colorize: true,
                    timestamp: true,
                    handleExceptions: true,
                    stderrLevels: ['error'],
                    humanReadableUnhandledException: true,
                    level: level,
                    label: category
                }),
                new winston.transports.File({
                    filename: 'logs/appLogs.txt',
                    maxsize: 5000000,
                    maxFiles: 20,
                    tailable : true,
                    timestamp: true,
                    handleExceptions: true,
                    humanReadableUnhandledException: true,
                    level: level,
                    label: category,
                    json: false
                })
            ]
        })

appLogs1.txt 现在是 9948153 字节,appLogs.txt 是 882922

标签: node.jswinston

解决方案


推荐阅读