Closed pxbos19 closed 8 months ago
Hi @pxbos19 , that is the right cfg to achieve your target...
Do you have a stack trace of the error?
I also suggest to check the error
and warning
events, they can help you understanding better...
accessLogStream.on("error", console.log);
accessLogStream.on("warning", console.log);
Sorry, but this doesn't help identifying the problem.
Could it be you initialize twice the rfs? In such case the first one will perform the rotation the second one gets the error.
Hope this helps
On Mon, Feb 19, 2024 at 4:22 AM pxbos19 @.***> wrote:
default.png (view on web) https://github.com/iccicci/rotating-file-stream/assets/155933151/aa490d76-95cf-43e4-b8fd-7054a4afcf16 I tested it by generating a log file at intervals of 30 seconds. When I judged whether the file existed, the file had not been generated yet, which resulted in an error.
— Reply to this email directly, view it on GitHub https://github.com/iccicci/rotating-file-stream/issues/99#issuecomment-1951625371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGWPFVF5TACIXSL6SXNDVDYULAOJAVCNFSM6AAAAABC3H6LTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJRGYZDKMZXGE . You are receiving this because you were assigned.Message ID: @.***>
it's done,thanks
My configuration is as follows: log.js :
function pad(number) { return number < 10 ? '0' + number.toString() : number.toString(); }
function generator(time) { if (!time) return 'cmt.log'; const year = time.getFullYear(); const month = pad(time.getMonth() + 1); const day = pad(time.getDate());
return
cmt.${year}-${month}-${day}.log
; }// 创建一个流 const accessLogStream = rfs.createStream(generator, { interval: '1d', // 每天旋转 path: './mnt/log', maxfiles: 3 });
When four log files are generated in the mnt\log directory: cmt.log cmt.2024-02-04.log cmt.2024-02-05.log cmt.2024-02-06.log
An error occurred: Error: ENOENT: no such file or directory, rename 'xxx\mnt\log\cmt.log' -> 'xxx\mnt\log\cmt.2024-02-04.log'
Why does this problem occur? The effect I want is to keep the log file for 3 days, and delete the earliest time after 3 days to generate a new log file for the day.