Recent

Author Topic: LazLogger not writing to file until program exits  (Read 1269 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 537
    • MarcusFernstrom.com
LazLogger not writing to file until program exits
« on: July 17, 2024, 11:10:37 pm »
I'm writing a CLI program and run into something odd.

Trying to use LazLogger and output to a file, but LazLogger isn't actually writing anything to the file until the program exits.

The file is created when the application starts but remains empty until it ends.

Example program:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   CRT, LazLogger;
  7.  
  8. begin
  9.   DebugLogger.LogName:='lazloggercli.log';
  10.   DebugLn('Testing the debug log output.');
  11.   Delay(10000);
  12. end.
  13.  

Surely this isn't the expected behaviour of a logging utility?
Am I missing something?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10551
  • Debugger - SynEdit - and more
    • wiki
Re: LazLogger not writing to file until program exits
« Reply #1 on: July 18, 2024, 12:52:09 am »
It's probably missing a flush somewhere. You could report this as a bug.

In the meantime, there is a property CloseLogFileBetweenWrites. But it's not on the baseclass, only on the class TLazLoggerFile used in the LazLogger unit.

So if you use the LazLoggerBase unit, to switch off logging, then that does not compile.

Trenatos

  • Hero Member
  • *****
  • Posts: 537
    • MarcusFernstrom.com
Re: LazLogger not writing to file until program exits
« Reply #2 on: July 18, 2024, 04:11:10 am »
Thanks Martin, adding DebugLogger.CloseLogFileBetweenWrites := true; did the trick.

I'll still probably report it as a bug but this solves my immediate need.

 

TinyPortal © 2005-2018