Forum > macOS / Mac OS X

Using LazLogger to Write Log File to Terminal

(1/2) > >>

c_knowles4834:
Hello all,

Recently, I have been working on a simple calculator program and found the need to trace the inputs the user gives the program and corresponding outputs for debugging purposes. I found that Lazarus comes with a unit called "LazLogger" and it seems like it will create a log file that can be displayed in a separate terminal window; however, I am not sure how to configure and implement the necessary changes to my source code to fulfill this function.  I would like the input and output to be displayed in a terminal window like so:

 
--- 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";}};} --- Start of Calc Trace<Date MMDDYYYY= "8/22/2021"/><Time HH:MM:SS XM= "15:01:05"/>1 btn3_OnClick 32 btnDec_OnClick 3.3 btn1_OnClick 3.14 btn4_OnClick 3.145 btn1_OnClick 3.1416 btn5_OnClick 3.14157 btn9_OnClick 3.14159
Does anyone know if LazLogger has this capability or will I have to create some new source code separate from the LazLogger unit to fulfill this function?

Thanks!

Below are my system parameters:

macOS: BigSur 11.5.2
Lazarus 2.0.12 x86_64-macosx
fpc-3.2.0.intel-macosx
fpc-src-3.2.0-2


Martin_fr:
https://wiki.lazarus.freepascal.org/LazLogger
See units LazLogger and LazLoggerBase.

Default is to write to the terminal, if a terminal is open. If no terminal is open, then nothing is written, unless a logfile is given.

You need to insert "debugln" into your source.
"btn3_onClick" is just text. It will not be done automatically.
But you can use code templates to pre-fill -> tools > code templates
and define "d" as:

--- 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";}};} ---debugln(['$ProcedureName() '|]);

When running from the IDE, you should be able to set a terminal in the global debugger settings (Tools > Options)

c_knowles4834:
Thanks for the help Martin!

Could I ask though for an example of how to implement "debugln" into my source code? 

I am quite new to Pascal, Lazarus, and programming at this level to fully understand what I must do in the source code to implement your suggestion.   

I apologize in advance for any inconvinence.

Martin_fr:

--- 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";}};} ---uses LazLogger; procedure Foo;begin  debugln('Doing Foo');  debugln(['Doing Foo', dbgs(SomeInt)]);  debugln('Forrmat like %s %i', ['Doing Foo', SomeInt]);end; 

Make sure to run the app from a console.

replace "uses LazLogger; " with "uses LazLoggerDummy; " and no output will be generated

It is similar to "writeln". But, it does not give an error if stdout is closed. On the otherhand, it is a normal function, so some of the magic of writeln is not avail.

Also you can control it when calling your app

yourapp --debug-log=file
(On Mac you may need to specify inside the bundle / no idea)

c_knowles4834:
Thanks Martin!

I got it to work flawlessly with your suggestions.  But, I had a question about a message I get when compiling my program:

"vsmcalculatorunit.pas(154,8) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined"

What does that mean?

Navigation

[0] Message Index

[#] Next page

Go to full version