Error when logrotate and compressed a log file being tailed
See original GitHub issueHi @iccicci ,
I have my stream config as follow:
{ interval: '10s', compress: (source, dest) => 'cat ${source} | gzip -c9 > ${dest}.gz', maxFiles: 3 }
I was monitoring the log file with tail -F, when it comes to the rotation time, it did not generate the .gz file and the writing stream was stopped
I have received the error message as follow:
{ [Error: EPERM: operation not permitted, stat 'C:\git\***\log\access.log'] errno: -4048, code: 'EPERM', syscall: 'stat', path: 'C:\\git\\***\\log\\access.log' }
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:411:19)
at writeOrBuffer (_stream_writable.js:399:5)
at RotatingFileStream.Writable.write (_stream_writable.js:299:11)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Logrotate Error: Unable to open ... for compression
It means that /var/log/mylog.1 does not exist or the permissions/ownership do not allow that file to be compressed.
Read more >Continuously monitor logs with tail that are occasionally rotated
As far as I understand, the problem is that when the log is rotated, there is a new file created, and the running...
Read more >logrotate(8) - Linux manual page - man7.org
It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it ......
Read more >Rotating Logs With Logrotate in Linux - Baeldung
logrotate is a log managing command-line tool in Linux. ... Specifically, any log files that are matched will be compressed upon rotation.
Read more >Why doesnt "tail" work to truncate log files? - Stack Overflow
... of the log rotate 5 # rotate once the file is bigger than 2k size 2k # don't error if the file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @FelixChow ,
first of all, which version of the package are you using?
From the error reported it’s clear we are facing a permissions problem. Looking at the filename it seems to be the not rotated filename while the reported problem is about rotation; this makes me think you have right privileges on that file. What I don’t know is tail behavior under Windows. Could it be the root cause of the problem? Do you have the same experience without the tail command in execution?
As last (but this is not related with your problem), in your compressor function you are adding
".gz"
at the destination file and you are using history (maxFiles: 3
); the package remembers the destination file it generates, it can’t know you are adding that extension; so history won’t work as expected. If you want to add an extension to the filename it’s better to use a filename generator function doing that and keep untouched the destination file name in the compressor function.Please let me know, iCC
I have just experienced the same issue, and found that is causes by race condition of workers. When deployed with pm2, the application has no master, and all cluster workers are writing to the same file path, which conflicts with each other.
To solve this problem, I added a leader election to workers to make sure only one worker can rotate the log file. I hope this rts module could provide manually start/stop rotation.