Forum > Options

How to use the Event Log?

<< < (2/4) > >>

piola:
The event log seems to be a quite useful feature. I recently stumbled upon it by chance. However there are two "but"s which are a bit irritating:

1. As written on the wiki page, OutputDebugString requires the Windows unit and is platform-specific. I'm not a big fan of including the Windows unit and try to avoid it whenever possible.

2. TCustomApplication.Log would be a really great place to act as a default for logging. But I don't know how to handle it ("if it has been implemented") so that log messages appear in the Lazarus event log.

So my request is to provide a minimal application which shows how to connect TCustomApplication.Log to the Lazarus event log.

Thank you!

Martin_fr:
Well "logging" (application sent messages) is only one aspect of the event log. (and windows specific)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;uses windows;begin  OutputDebugStringA('abc');end. 
You may need to configure the event log to show the message  / right click and look at the options.


You can also use "breakpoint actions"
See bottom of: https://wiki.freepascal.org/IDE_Window:_Breakpoints#Breakpoint_properties

Mind that this is rather slow, if you have a lot of messages...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;procedure MyLog(a: Ansistring);begin  a := a;end; begin  MyLog('abc');  MyLog('def');end.
With a breakpoint on line 4, that
- does not break
- Evaluate the expression "a"

Again, ensure you have the right options enabled for the event log.


In the above case, you can also use debug history (take snapshot). It will snapshot all your watches.  But you must select each entry to read any of the recorded data. So while you get more data, it is less convenient to read.
https://wiki.freepascal.org/IDE_Window:_Debug_History

Martin_fr:
IIRC there is somewhere an independent "debug server" (not using the event log). It has its own server to show the messages, and a unit with methods to sent the messages from the debugger app. But you may as well log to a file and use "tail". (though debug server, wouldn't have "flush" delays).

However, I have this only from hear-say, and can't provide any further details....

Martin_fr:
If you are looking for such a logging facility, because you have data (variable/properties) that either due to their type or accessor are hard to get in the watches window...

That is a matter of finding out once, how to get the date. E.g.: Typecasts, or finding the field(s) if a property can't be called.

FpDebug and DWARF-3
TStringlist can be shown with

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---(l.FList)^[0..l.FCount-1].FString
"Debug Inspector" can be used to build such an expression.

https://wiki.freepascal.org/FpDebug-Watches-Intrinsic-Functions#Array_slice_MyArray.5Bn..m.5D_with_mapping

Further more you may try (should work, but haven't tested on all platforms)


--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---l.Get(1)l.GetTextStr()
You need to enable function calling on each watch, and globally in the Tool>Options>Debugger

Martin_fr:
For logging to a file, I usually use lazlogger (search wiki).

It has DebuglnEnter/DebuglnExit to log with indent.

But it does not log to the debugger. Only to files or console

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version