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+)");
....
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: