RTC Forums

Subscription => Support => Topic started by: Theprasit on November 23, 2014, 06:30:19 AM



Title: rtcLog : Setting global VAR
Post by: Theprasit on November 23, 2014, 06:30:19 AM
Hi Danijel,

Just a discussion for better workaround.

When using rtcLog for basic logging, we can change setting eg. LOG_FOLDER, LOG_THREADID and StartLog with new setting changed.
But when activate RTC_DEBUG, the default setting is used because rtcLog do StartLog in it's unit Initialization section. This will result in different log file locations.

For workaround solution, is to modify global var in rtcLog but this is not a properly way when we do update to a new version.

Do you have any ideas to settle this?

Best Regards,

Theprasit


Title: Re: rtcLog : Setting global VAR
Post by: D.Tkalcec (RTC) on November 23, 2014, 09:55:12 AM
If you want to change the logging folder and other global variables in the rtcLog unit before the actual logging starts, you can  ...

1. Create a new unit in your Project folder. I will call it "MyDebug.pas" here, but you can call it anything you want.

2. In your new unit (myDebug.pas), ONLY use the rtcLog unit from the RTC SDK.
    Do NOT use any other units from the RTC SDK and do NOT use any units which might be using any RTC unit.

3. In the initialization section of your new unit, set all the logging variables to the values you want to use.

4. In your Project file (DPR), add your new unit to the "uses" clause before any other RTC or user units, so it will be loaded first.

Example "myDebug.pas" unit:

unit myDebug;
interface
uses rtcLog;
implementation
initialization
// here, you can set up all the logging variables ...
RTC_LOG_THREADID:=True;
end.

Example myProject (DPR) modification ...

program myProject;
uses
  // if you are using a custom memory manager like "FastMM", add it here:
  FastMM4,
  // use your new debug unit before using any other units:
  myDebug,
  // here comes the rest ...

This way, you can override all global variables in the rtcLog unit before the actual logging starts. Even though the StartLog procedure will be called from the rtcLog unit before you start changing the variables, it only sets the "doLog" variable to TRUE, but it does NOT start writing anything to disk. Only the actual use of logging functions creates log files and writes to the disk.

Best Regards,
Danijel Tkalcec


Title: Re: rtcLog : Setting global VAR
Post by: Theprasit on November 26, 2014, 09:45:28 AM
Hi Danijel,

It's a clear and nice solution, work great.

Thank you and Best Regards,

Theprasit