Wednesday, October 27, 2010

How to log

It is always very important to log (at least in real world applications) what's going on in the application in order to  review actions that have already passed.

In BB.Log there is helpful class called TLog and TLogHandler tha main features are:

  • Concurrent, we use it at work in applications with many threads writing to the same file.
  • Multi file, you might need more than one file 
    • for instance ChessKISS logs to three different files
      • One for the Winboard protocol
      • One for internal errors
      • And the lat one for printing the board on every move (useful for revising games)
  • Prefixes, timestamp and headers are writed on every entry
  • Auto creates folders per date if desired.
The handler helps the maintenance of the different logs, this is how to use it:


var
  log: TLog;

begin
  log := TLogHandler.Instance.Add('log.txt', 'logs\');
  log.Add('Initializing');
  log.Add('Executing';
  log.Add('Finalizing');
end;
If you nneed more logs just add another one via TLogHandler.
I hope it helps

No comments:

Post a Comment