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

FileAppender write in the wrong position. #72

Closed
TikoTako opened this issue Mar 13, 2023 · 5 comments
Closed

FileAppender write in the wrong position. #72

TikoTako opened this issue Mar 13, 2023 · 5 comments
Assignees
Labels
accepted Issue has been accepted and inserted in a future milestone enhancement
Milestone

Comments

@TikoTako
Copy link

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.

TikoTako added a commit to TikoTako/loggerpro that referenced this issue Mar 13, 2023
@danieleteti
Copy link
Owner

Can you reproduce the error please?

@TikoTako
Copy link
Author

Can you reproduce the error please?

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

@luebbe
Copy link
Contributor

luebbe commented Jun 22, 2023

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.

@danieleteti
Copy link
Owner

danieleteti commented Jun 22, 2023

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.

@danieleteti danieleteti added this to the 1_5_0 milestone Jun 22, 2023
@danieleteti danieleteti added enhancement accepted Issue has been accepted and inserted in a future milestone and removed question labels Jun 22, 2023
@danieleteti danieleteti self-assigned this Jun 22, 2023
@TikoTako
Copy link
Author

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

danieleteti added a commit to danieleteti/delphimvcframework that referenced this issue Oct 18, 2023
0d39e1d1 New LogLevel: FATAL
5248b9de Improved fileformatname check
657a539d danieleteti/loggerpro#79
67729f57 danieleteti/loggerpro#72
f05a91a6 danieleteti/loggerpro#73
3c805c0f Merge pull request #71 from luebbe/master
3a790459 Fixes #70 Add test to expose #70

git-subtree-dir: lib/loggerpro
git-subtree-split: 0d39e1d1549d42fa20b71503eed944043771b7bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Issue has been accepted and inserted in a future milestone enhancement
Projects
None yet
Development

No branches or pull requests

3 participants