LazLogger

From Lazarus wiki
Revision as of 06:50, 24 October 2015 by Mattias2 (talk | contribs) (→‎File)
Jump to navigationJump to search

Overview

LazLogger is supplied with Lazarus and provides logging to file.

It has not been tested with multithreaded applications as mentioned in the Lazarus mailing list in April 2014.

Usage

Adding logging support to your source code

(For historical reasons some parts are also accessible through LclProc; this access might be removed in future)

By just including the unit you can use the following:

  • DebugLn: which works about the same as WriteLn, but accepts only strings.
  • DebugLnEnter/DebugLnExit: same as debugln, but increase/decrease indent.
  • DbgOut: which works about the same as Write, but accepts only strings.

All of them can be called with either:

  • A single string, or list of (up to 15) strings: DebugLn('Foo'); DbgOut('a','b');
  • An array of const: DebugLn(['Foo=', 1]);
  • Same arguments as Format(). String + array of const: DbgOut('a %d',[1]);

Tip: use LazLoggerDummy in your uses clause if you want to disable all logging but don't want to have to change all your code.

Logging output

Stdout

In normal circumstances, the output is written to stdout. No output is written if stdout is closed - for example when the application is {$AppType Gui}, or compiled with -WG on Windows (see Compiler options / Linking / Target OS specific options).

File

Debug output can also be written to file. The initialization code of the logging unit

  • checks your program's command line parameters for '--debug-log=<file>'. On finding this parameter, any subsequent debug output is sent to <file>.
  • If no '--debug-log' command line parameter has been given, it next checks if an operating system environment variable xxx_debuglog exists, where xxx is the program file name without extension. E.g. for Lazarus this would be lazarus_debuglog. If such an environment variable exists, it uses the file specified in that environment variable as file to receive debug output.

Example: if you do:

set lazarus_debuglog=c:\lazarus\debug.txt

and run Lazarus, debug output will be written to c:\lazarus\debug.txt.

Debug server

Not available in LazLogger; see DebugServer.

Documentation

For more features, see the unit itself and the LCL documentation.

See also