bengeisler / TcLog

Flexible logging functionality for TwinCAT 3.
MIT License
54 stars 10 forks source link

TcLog not writing to file system #31

Closed Stenters closed 1 week ago

Stenters commented 1 week ago

This may be a user issue, but I have followed the configuration as per the documentation, and while I can log to ADS, I cannot write logs to the filesystem. Any advice on what the issue may be would be appreciated! My setup is the following:

Main Variable list

...
// Logger
VAR
  _coreLogger : TcLogLib.TcLogCore(bufferSize := 100 * (UDINT_TO_DINT(Tc2_System.MAX_STRING_LENGTH) + TcLogLib.Constants.FifoOverhead));
END_VAR
...

Main Body

IF NOT initialize() THEN
    RETURN;
END_IF

stateMachine();
system(isSimulation := isSimulation);
_coreLogger();

Main.initialize() Body


IF isInitialized THEN
    initialize := TRUE;
    RETURN;
END_IF

// Set isInitialized, then allow it to be reset if any component isn't initialized
isInitialized := TRUE;

// Use the set command, which cannot make a BOOL TRUE
isInitialized S= stateMachine.initialize();

IF isDebug THEN
    _coreLogger
        .WriteToAds()
        .WriteToFile('c:\Kie Solution\', 'PLC_LOGS.txt')
        .SetRollingInterval(RollingIntervals.Monthly)
        .MinimumLevel(TcLogLib.LogLevels.Debug)
        .IncludeInstancePath()
        .RunLogger();
ELSE
    _coreLogger
        .WriteToAds()
        .WriteToFile('c:\Kie Solution\', 'PLC_LOGS.txt')
        .SetRollingInterval(RollingIntervals.Monthly)
        .MinimumLevel(TcLogLib.LogLevels.Warning)
        .IncludeInstancePath()
        .RunLogger();
END_IF

GlobalFBs.Logger.SetLogger(_coreLogger);

initialize := isInitialized;
bengeisler commented 1 week ago

Hi, there are two things:

First, please always run your core logger. Right now, as soon as it's initialised it will not get called anymore. It should run in every cycle of the PLC. See the first code snippet in the Readme.

Second, if the first suggestion doesn't solve the issue try removing the whitespace from your path.

Stenters commented 1 week ago

That was it! I moved the core logger RunLogger() method to the main program, and it works now! Thank you!