TcLogCore
- Namespace
- TcLogLib
- Implements
-
__System.IQueryInterface
TcLogCore
provides the base functionality of the logger and sets the configuration.
The logger can be configured by calling its methods that set the configuration.
Note
TcLogCore.RunLogger()
should be called once each cycle. The configuration methods should be called before
RunLogger
is called.
When declaring an instance of TcLogCore, the ininital buffer size has to be set. If the buffer size is set too low, it will expand automatically if enough memory is available.
To set the inital buffer size to accomodate 100 messages, use it like this:
VAR
myLogger: TcLogCore(BufferSize := 100 * (Tc2_System.MAX_STRING_LENGTH * Constants.FifoOverhead));
END_VAR
FUNCTION_BLOCK TcLogCore IMPLEMENTS TcLogLib.ILogCore, __System.IQueryInterface
Constructor
FB_init
METHOD FB_init (
bInitRetains : BOOL,
bInCopyCode : BOOL,
bufferSize : UDINT) : BOOL
Inputs
bInitRetains
BOOLbInCopyCode
BOOLbufferSize
UDINTInitial buffer size for the internal log message buffer
Returns
- BOOL
Properties
Busy
Busy
evaluates to TRUE
as long as the log file is kept open to append new log messages
or there are pending messages in the queue to be written to the logfile.
PROPERTY Busy : BOOL
Property Value
- BOOL
Configuration
Returns the current configuration of the logger.
PROPERTY Configuration : LoggingConfiguration
Property Value
Error
Returns information about internal errors.
PROPERTY Error : REFERENCE TO Error
Property Value
- REFERENCE TO Error
TimeInfoReady
TimeInfoReady
evaluates to TRUE
once the time information used by determine
the timestamp for the message is available.
PROPERTY TimeInfoReady : BOOL
Property Value
- BOOL
Methods
BuildLoggingConfiguration
METHOD PRIVATE BuildLoggingConfiguration () : BOOL
Returns
- BOOL
DeleteLogFilesAfterDays
Configuration method which sets the lifespan of log files. Once exceeded, they will be deleted.
METHOD DeleteLogFilesAfterDays (
lifespan : UINT) : REFERENCE TO TcLogCore
Inputs
Returns
- REFERENCE TO TcLogCore
FlushCache
Flushes the logging cache. All messages that have not yet been processed will be lost.
METHOD FlushCache () : BOOL
Returns
- BOOL
IncludeInstancePath
Configuration method. If this method is called, the instance path where the log messages has been triggered will be included in the log message.
METHOD IncludeInstancePath () : REFERENCE TO TcLogCore
Returns
- REFERENCE TO TcLogCore
LogCustomFormat
Logger method. It should only be called from within objects that implement ILog
.
Logs data in custom format. No additional formatting will be done.
METHOD LogCustomFormat (
data : Tc2_System.T_MaxString) : BOOL
Inputs
Returns
- BOOL
LogStandardFormat
Logger method. It should only be called from within objects that implement ILog
.
Logs in the standard format. This includes
- timestamp
- log level
- log message
- instance path of logging source (optional) The message will only be logged if the logging level exceeds the configured minimum logging level.
METHOD LogStandardFormat (
data : Tc2_System.T_MaxString,
instancePath : Tc2_System.T_MaxString,
logLevel : LogLevels) : BOOL
Inputs
data
Tc2_System.T_MaxStringData to be logged.
instancePath
Tc2_System.T_MaxStringInstance path of calling logger to locate source of logging message.
logLevel
LogLevelsLog level of message.
Returns
- BOOL
MinimumLevel
Configuration method. Sets the minimum log level. Log messages below this level will not be logged.
METHOD MinimumLevel (
level : LogLevels) : REFERENCE TO TcLogCore
Inputs
level
LogLevelsMinimum log level to be logged.
Returns
- REFERENCE TO TcLogCore
RunLogger
Cyclic method of Logger. This method has to be executed in every plc cycle and runs all internal methods that have to be executed cyclically.
Note
This method should be the last method of TcLogCore
to be called in each cycle.
METHOD RunLogger () : BOOL
Returns
- BOOL
SetDelimiter
Configuration method Sets delimiter between different columns of log file.
METHOD SetDelimiter (
delimiter : STRING(1)) : REFERENCE TO TcLogCore
Inputs
Returns
- REFERENCE TO TcLogCore
SetRollingInterval
Configuration method. Sets the rolling interval of the log file. Once the rolling interval expires, a file name with a new timestamp will be generated.
METHOD SetRollingInterval (
interval : RollingIntervals) : REFERENCE TO TcLogCore
Inputs
interval
RollingIntervalsRolling interval for log file. Once exceeded, a new log file will be created.
Returns
- REFERENCE TO TcLogCore
TimestampFormat
Configuration method. Sets the format of the timestamp in the file name.
The following format options are available: Y : year M : month D : day h : hour m : minute s : second i : millisecond
Example: YYMMDD-hh:mm:ss:iii => 20210812-12:30:22:123
METHOD TimestampFormat (
format : STRING) : REFERENCE TO TcLogCore
Inputs
Returns
- REFERENCE TO TcLogCore
ValidTimestampsOnly
Configuration method. If this method is called, only valid timestamps are logged. Note that using this configuration will skip logging anything during the first few PLC cycles, as TwinCAT needs a few cycles to initialize its time information.
METHOD ValidTimestampsOnly () : REFERENCE TO TcLogCore
Returns
- REFERENCE TO TcLogCore
WriteToAds
Configuration method. If this method is called, the logs will be written to ADS.
METHOD WriteToAds () : REFERENCE TO TcLogCore
Returns
- REFERENCE TO TcLogCore
WriteToFile
Configuration method. If this method is called, the logs will be persisted to the file system.
METHOD WriteToFile (
path : Tc2_System.T_MaxString,
fileName : STRING) : REFERENCE TO TcLogCore
Inputs
path
Tc2_System.T_MaxStringFile path the logs will be written to.
fileName
STRINGFile name of the log file. Will automatically be prefixed by timestamp.
Returns
- REFERENCE TO TcLogCore