danieleteti/loggerpro

FileAppender write in the wrong position.

TikoTako opened this issue · 5 comments

Hello,
i have a global ILogWriter that is called from the dpr and from a main unit.
Before the program close i have one last debug write on the dpr, when that happens it write back in the last position it had on the last write (done in the dpr), so it overwrite some of the log done while in the main unit.

Can you reproduce the error please?

Can you reproduce the error please?

Here:
https://github.com/TikoTako/loggerpro-test

luebbe commented

I have seen this offset sometimes as well, but never took a closer look. I attributed it to two instances of the application running in parallel and writing into the same log file (when the PID is not used in the file name). But @TikoTako 's log shows that it is obviously written from the same thread.

I deeply investigated the problem (I never seen it in years).The problem is the file name format which doesn't contain placeholders so output files are overlapped.
When you pass a filenameformate which doesn't contain placeholders, the filename is not deparated by TAG and all writers writes on the same file. The problem is that current code doesn't check this situation. I added the following check in constructor.

procedure TLoggerProFileAppenderBase.CheckLogFileNameFormat(
  const FileNameFormat: String);
var
  lExt: string;
begin
  lExt := Format(FileNameFormat, ['X','Y','Z']);
  if lExt = FileNameFormat then {means that FileNameFormat doesn't contain place holders }
  begin
    raise ELoggerPro.CreateFmt(
      'FileName Format "%s" doesn''t contain required placeholders. [HINT: Just as an example, the DEFAULT_FILENAME_FORMAT is "%s"]',
      [FileNameFormat, DEFAULT_FILENAME_FORMAT]);
  end;
end;

Can you check if, using the repo version without your changes, it works?

If you don't want to have separate files by tag, just use TLoggerProSimpleFileAppender.

With TLoggerProSimpleFileAppender and one file the order is correct, also is ok with TLoggerProFileAppender if it use different log files (one each unit)