• User guide
  • API Reference
Show / Hide Table of Contents
  • TcLogLib
    • Constants
      • Constants
    • Logger
      • TcLog
      • TcLogCore
      • TcLogTrig
      • ErrorCodes
      • LogLevels
      • RollingIntervals
      • Error
      • LoggingConfiguration
      • ILog
      • ILogCore
    • Utils
      • AnyToString
      • DateTime

TcLogCore

Implements
TcLogLib.ILogCore
__System.IQueryInterface
Namespace: TcLogLib
Declaration
{attribute 'hide_all_locals'}
FUNCTION_BLOCK TcLogCore IMPLEMENTS TcLogLib.ILogCore, __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

Constructor

FB_init

Declaration
METHOD FB_init (
 bInitRetains : BOOL,
 bInCopyCode : BOOL,
 bufferSize : UDINT) : BOOL
Inputs
Name Type Description
bInitRetains BOOL
bInCopyCode BOOL
bufferSize UDINT Initial buffer size for the internal log message buffer

Properties

Busy

Declaration
{attribute 'monitoring':='call'}
PROPERTY Busy : BOOL

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.

Configuration

Declaration
{attribute 'monitoring':='variable'}
PROPERTY Configuration : LoggingConfiguration

Returns the current configuration of the logger.

Error

Declaration
{attribute 'monitoring':='call'}
{attribute 'suppress_wrn_C0410'}
PROPERTY Error : REFERENCE TO Error

Returns information about internal errors.

TimeInfoReady

Declaration
{attribute 'monitoring':='call'}
PROPERTY TimeInfoReady : BOOL

TimeInfoReady evaluates to TRUE once the time information used by determine the timestamp for the message is available.

Methods

DeleteLogFilesAfterDays

Configuration method which sets the lifespan of log files. Once exceeded, they will be deleted.

Declaration
METHOD DeleteLogFilesAfterDays (
 lifespan : UINT) : REFERENCE TO TcLogCore
Inputs
Name Type Description
lifespan UINT Lifespan of logfiles in days.

FlushCache

Flushes the logging cache. All messages that have not yet been processed will be lost.

Declaration
METHOD FlushCache () : 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.

Declaration
METHOD IncludeInstancePath () : 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.

Declaration
METHOD LogCustomFormat (
 data : Tc2_System.T_MaxString) : BOOL
Inputs
Name Type Description
data Tc2_System.T_MaxString Data to be logged.

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.
Declaration
METHOD LogStandardFormat (
 data : Tc2_System.T_MaxString,
 instancePath : Tc2_System.T_MaxString,
 logLevel : LogLevels) : BOOL
Inputs
Name Type Description
data Tc2_System.T_MaxString Data to be logged.
instancePath Tc2_System.T_MaxString Instance path of calling logger to locate source of logging message.
logLevel TcLogLib.LogLevels Log level of message.

MinimumLevel

Configuration method. Sets the minimum log level. Log messages below this level will not be logged.

Declaration
METHOD MinimumLevel (
 level : LogLevels) : REFERENCE TO TcLogCore
Inputs
Name Type Description
level TcLogLib.LogLevels Minimum log level to be logged.

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.

Declaration
{attribute 'hide_all_locals'}
METHOD RunLogger () : BOOL

SetDelimiter

Configuration method Sets delimiter between different columns of log file.

Declaration
METHOD SetDelimiter (
 delimiter : STRING(1)) : REFERENCE TO TcLogCore
Inputs
Name Type Description
delimiter STRING(1) Delimiter between different columns of log file.

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.

Declaration
METHOD SetRollingInterval (
 interval : RollingIntervals) : REFERENCE TO TcLogCore
Inputs
Name Type Description
interval TcLogLib.RollingIntervals Rolling interval for log file. Once exceeded, a new log file will be created.

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

Declaration
METHOD TimestampFormat (
 format : STRING) : REFERENCE TO TcLogCore
Inputs
Name Type Description
format STRING Format the timestamp should have.

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.

Declaration
METHOD ValidTimestampsOnly () : REFERENCE TO TcLogCore

WriteToAds

Configuration method. If this method is called, the logs will be written to ADS.

Declaration
METHOD WriteToAds () : REFERENCE TO TcLogCore

WriteToFile

Configuration method. If this method is called, the logs will be persisted to the file system.

Declaration
METHOD WriteToFile (
 path : Tc2_System.T_MaxString,
 fileName : STRING) : REFERENCE TO TcLogCore
Inputs
Name Type Description
path Tc2_System.T_MaxString File path the logs will be written to.
fileName STRING File name of the log file. Will automatically be prefixed by timestamp.
In this article
Back to top Documentation powered by zkdoc