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

Rotation file counter issue on process restart #101

Open
jeromevalentin opened this issue Aug 10, 2023 · 0 comments
Open

Rotation file counter issue on process restart #101

jeromevalentin opened this issue Aug 10, 2023 · 0 comments

Comments

@jeromevalentin
Copy link

jeromevalentin commented Aug 10, 2023

I'm using winston-daily-rotate-file in version 4.7.1, referencing file-stream-rotator in version 0.6.1.

How to reproduce?

  • Start a process logging intensively

  • Define a size limit of 200k AND a max_files of 3 and a fixed audit file and use regex special character in the log file name ( "myProcess-%DATE%-[ thread]" for example)

  • Wait for the creation of the 3 files, ensure the system is writing inside the ".log.3" file

  • Stop and ReStart the process within the same conditions

  • DEFECT: The file ".log" is recreated and the new incoming logs are going inside .... the ".log.3" remains not filled to 200k and the rotating numbering is restarting with ".log.1" ...

Defect

The internal rotation counter used to determine the "current" logging file is not extracted correctly from the content of the given audit file. The log file is matched directly to the last entry of audit file.

Consequences:

Analyzing logs becomes really complicated as if the process is restarted automatically (in case of failure .... meaning when logs are the most useful), the ordered of the logged files are not readable easily along the time.

Proposed Fix

Escape the whole log file name prior to perform filename matching by using standard:

...
    function escapeRegExp(string) {
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
    }

    var lastEntry = auditLog.files[auditLog.files.length - 1].name;
    if(lastEntry.match(escapeRegExp(t_log))){
        var lastCount = lastEntry.match(t_log + "\\.(\\d+)");
....
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