Difference between revisions of "LazLogger"
(debug server (provisionally)) |
|||
Line 17: | Line 17: | ||
* An array of const: DebugLn(['Foo=', 1]); | * An array of const: DebugLn(['Foo=', 1]); | ||
* Same arguments as Format(). String + array of const: DbgOut('a %d',[1]); | * Same arguments as Format(). String + array of const: DbgOut('a %d',[1]); | ||
+ | |||
+ | Tip: use <code>LazLoggerDummy</code> in your uses clause if you want to disable all logging but don't want to have to change all your code. | ||
=== Logging output === | === Logging output === | ||
+ | ==== Stdout ==== | ||
In normal circumstances, the output is written to <code>stdout<code>. No output is written if <code>stdout</code> is closed - for example when the application is {$AppType Gui}, or compiled with -WG on Windows (see Compiler options / Linking / Target OS specific options). | In normal circumstances, the output is written to <code>stdout<code>. No output is written if <code>stdout</code> 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 | 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 paramete, any subsequent debug output is sent to <file>. | * checks your program's command line parameters for '--debug-log=<file>'. On finding this paramete, any subsequent debug output is sent to <file>. | ||
Line 31: | Line 35: | ||
and run Lazarus, debug output will be written to c:\lazarus\debug.txt. | and run Lazarus, debug output will be written to c:\lazarus\debug.txt. | ||
− | For more features, see the unit. | + | ==== Debug server ==== |
+ | to do: this is actually probably a different unit than lazlogger - debugintf | ||
+ | You can also send the output to a debug server application. A debug server application is included with Lazarus; you can compile | ||
+ | $(LazarusDir)/tools/debugserver/debugserver.lpi | ||
+ | and set it up as an external tool: | ||
+ | $(LazarusDir)/tools/debugserver/debugserver$(ExeExt) | ||
+ | |||
+ | To use it, add <code>dbugintf</code> to the uses clause of the units you want to debug, then use SendDebug to send messages to the debug server. | ||
+ | |||
+ | == Documentation == | ||
+ | For more features, see the unit itself and the LCL documentation. | ||
== See also == | == See also == |
Revision as of 11:36, 9 May 2014
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 paramete, 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
to do: this is actually probably a different unit than lazlogger - debugintf
You can also send the output to a debug server application. A debug server application is included with Lazarus; you can compile
$(LazarusDir)/tools/debugserver/debugserver.lpi
and set it up as an external tool:
$(LazarusDir)/tools/debugserver/debugserver$(ExeExt)
To use it, add dbugintf
to the uses clause of the units you want to debug, then use SendDebug to send messages to the debug server.
Documentation
For more features, see the unit itself and the LCL documentation.
See also
- TEventLog documentation Built in support for logging in FPC/Lazarus
- MultiLog
- log4delphi