Log Rotate does nort work properly: why?
Closed this issue · 6 comments
Hi,
I used
_Log := BuildLogWriter([
TLoggerProFileAppender.Create(10, 1000,
'..\proglog',
[],
'%0:s %1:2.2d '+
System.StrUtils.ReplaceStr(GetLoggedOnUser+' ON '+
GetRealComputerName,'.','_')+' AT '+
System.SysUtils.FormatDateTime('yyyymmddhhnnsszzz',System.SysUtils.now),
DEFAULT_LOG_FORMAT)]);
and got (on a certain session) a 32 k file containig all my log-messages:
>dir
My-Prog 00 nmm ON My-Comnputer AT 20240301091109558 32.475 01.03.2024 09:12 -a--
but if I use
_Log := BuildLogWriter([
TLoggerProFileAppender.Create(90, 5,
'..\proglog',
[],
'%0:s %1:2.2d '+
System.StrUtils.ReplaceStr(GetLoggedOnUser+' ON '+
GetRealComputerName,'.','_')+' AT '+
System.SysUtils.FormatDateTime('yyyymmddhhnnsszzz',System.SysUtils.now),
DEFAULT_LOG_FORMAT)]);
I got only two files
>dir
My-Prog 00 nmm ON My-Comnputer AT 20240301091317671 1.727 01.03.2024 09:13 -a--
My-Prog 01 nmm ON My-Comnputer AT 20240301091317671 5.255 01.03.2024 09:13 -a--
and many log-messages are missed (I performed exactly the same session as above),
What have I done wrong?
(I used your stable version 1.4.0)
(I also tried Version 2.0 beta, but this won't compile in Delphi 10.3 (because of use of embesdded var-constructs))
Regards
nmm
Any Idea?
yes.. a minimal modified version of 02_file_appender from the samples...
in LoggerProConfig.pas:
if you use ...TLoggerProFileAppender.Create(90, 5, ... then you get only two files 01 an d02 , one 5k, one 3k
when you klick "2000 Info": all Messages 1 to 1905 are lost.
If you use
TLoggerProFileAppender.Create(90, 10000,
you get only on file with all 2000 messages.
Regeards
Mircea
Without looking at the code: is it possible that the timestamp that you add to the file names is causing the confusion?
There are some problems:
- to make the log rotations happens, filename cannot depends by date/time
- the generated filenames seems to collide becaouse the format is not correct
Version 2 solved all these potential problems with custom filename formats. Please, try to use the version 2 (compatibility with older delphi version has been repristinated).
The only placeholders you can use in the file names are the following:
{module}: replaced with the module name
{number}: replaced with the index of the log file set
{tag}: log tag
{pid}: replaces with the process PID (optional) to mantain logs for different runs.
This is the initialization you should use in V2
_Log := BuildLogWriter([
TLoggerProFileAppender.Create(90, 10000,
'logs',
'{module}.{number}.{tag}.log'
)
]);
OK, Thank you for that information!