这可能有些晚了,针对您的问题,我最近找到了一个解决方案,但是也没有发现任何一种方法是理想的。 logrotate
是Linux下的C程序,而 pino-rotating-file
需要更改程序调用命令行以通过多个程序调用管道输出。
我还没有完成测试,但是目前我正在评估的解决方案是 rotating-file-stream
。它将旋转隐藏在文件流中,并与pino(至今)无缝协作。
主程序:
'use strict';
const path = require('path');
const pino = require('pino');
const logger = pino({
name: 'testing123',
level: 'trace',
transport: {
targets: [
{
target: path.resolve('transport-stream.js'),
level: 'trace',
options: {
append: true,
destination: path.resolve('delete-me.log'),
interval: '5s',
compress: 'gzip',
}
}
]
}
});
logger.info('started');
let counter = 1;
setInterval(() => {
logger.info(`interval #${counter}`);
}, 10_000);
transport-stream.js:
'use strict';
const {createWriteStream} = require('fs');
const rfs = require('rotating-file-stream');
module.exports = function(options) {
const { size, interval, compress } = options;
return rfs.createStream(options.destination, {
size: size || "1000B",
interval: interval || "10m",
compress: compress || "gzip",
});
}