Sign in Join
Wiki copytemporary

Enabling LazLogger and Application Exception Dump: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Enabling LazLogger and Application Exception Dump

OldNewLine
1+Since the release of Lazarus 2.0.0, LCL applications by default do no longer have LazLogger enabled, nor do they do an application exception dump (using debugln) when an application crashes (see: [[Lazarus 2.0.0 release notes|Lazarus_2.0.0_release_notes#No_default_LazLogger]] and [[Lazarus 2.0.0 release notes|Lazarus_2.0.0_release_notes#No_LCL_Application_exception_dump]] for an explantion why).
2+
3+Especially for the debug build mode of your application, it is very usefull to have these two features enabled.
4+In [[Lazarus 2.0.0 release notes|this section of the 2.0 releae notes]] it is suggested to add `-FaLCLExceptionStacktrace,LazLogger` to "Additions and Overrides" of the Compiler Options of the debug build mode.
5+While this works just fine on Windows, on Linux and Amiga (at least) this will cause your application to crash, since these units need a threadmanger to be active and using the "-Fa" option for the compiler wil load these units before any uses clause is parsed, so no threadmanager will activated yet.
6+
7+A different solution is to create a dedicated unit for the sole purpose of initializing application exception dumping and logging using debugln.
8+In this unit you will then make sure a threadmanager is used (as the first unit in the uses clause).
9+
10+Example:
11+```
12+unit LCLDebug;
13+ {$mode objfpc}
14+ {$h+}
15+
16+ {
17+ Activates logging and backtrace capabilities for Lazarus Applications
18+
19+ The recommended way to use this is by using the -Fa paramter for the compiler:
20+ -FaLCLDebug
21+
22+ This can be set in Project Options -> Cmpiler Options -> Custom Options in Lazarus IDE.
23+ The idea is that you uses this in the "debug" build mode.
24+
25+ You should use the LazLoggerBase unit in any unit from your program that uses the
26+ Debugln() procedure: it won't output anything by default.
27+ (Using LazLogger unit overrides this behaviour then).
28+
29+ Copyright (C) 2025 by FlyingSheep Inc. and Bart Broersma
30+ }
31+
32+ interface
33+
34+ uses
35+ {$IFDEF UNIX}
36+ cthreads,
37+ {$ENDIF}
38+ {$IFDEF HASAMIGA}
39+ athreads,
40+ {$ENDIF}
41+ LazLogger, //enables debugln() etc
42+ LCLExceptionStacktrace; //enables backtracing on exceptions
43+ implementation
44+
45+ initialization
46+ //empty section to fool the compiler that the unit actually does something, so it doesn't emit the "unit LCLDebug not used in ..." hint.
47+
48+ end.
49+```
50+
51+Now, in the compiler options for your debug build mode, you go to "Custom Options" and add "-FaLCLDebug" (without the quotes).
52+[![custom options lcldebug.png](/wiki-images/5/53/custom_options_lcldebug.png)](</File:custom_options_lcldebug.png>)
53+
54+---
55+*From the Free Pascal wiki, page "Enabling LazLogger and Application Exception Dump", as the Internet Archive kept it on 2026-01-05. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history