Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logrotate loses/ignores file extension when rotation occurs (myapp.err is rotated as myapp.2020-08-28_10-15-32.log) #160

Open
e-dot opened this issue Aug 28, 2020 · 2 comments

Comments

@e-dot
Copy link

e-dot commented Aug 28, 2020

I'm using pm2-logrotate - works fine but it ignores file extension when rotating. The file name always end with .log, even for error files (stderr).

Looking at source code it seems to be easy to fix on line 107:
var final_name = file.substr(0, file.length - 4) + '__' + final_time + '.log';

Simply reuse orignal file extension instead of hard-coded '.log'

Regards,

E.

@e-dot
Copy link
Author

e-dot commented Aug 28, 2020

Here's a simple fix (I'm preparing a patch for it):
// Get base file name - i.e. without file extension : remove everything after the last dot (up to then end of string)
var base_file_name = file.replace(/\.[^\.]+$/, '')
// Get file extension : replace everything by string after the last dot
var file_ext = file.replace(/^.*\.([^\.]*)$/i, '$1')
// Build final filename with base + time + extension
var final_name = base_file_name + '__' + final_time + '.' + file_ext;

Regards,

E.

@e-dot
Copy link
Author

e-dot commented Aug 28, 2020

Made a patch in this pull request : #161

E.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant