Table of Contents

LoggerBuffered7FF

Namespace
ZAux
Implements
FUNCTION_BLOCK LoggerBuffered7FF IMPLEMENTS ZCore.ILogger, ZCore.ILoggerBase, ZCore.ILoggerImperativeApi, ZCore.ILoggerFluentApi

This Logger buffers log entries, the buffer for this Logger is held internally and it is not needed to create a buffer instance externally in an application like for the LoggerBuffered. This Logger may store up to 2047 log messages (16#07FF).

A single log message has the following properties

  • LogLevel: Severity of a message
  • Timestamp: Timestamp that contains information about when a message was logged
  • Message: String that contains the actual information that should be logged.

These properties can be easily handled by utilizing a predefined logging-method (i.e. Debug, Trace) or the generic method LogMessageRef. While the predefined logging-methods automatically fill most properties of a log message, the generic method give the most control by providing a parameter for every property of a log message.

LoggerNameDecorator allows to modify these properties to provide extra information to a log-entry. One possible application of this feature is to prefix the Message property. For example, a unit may prefix every message with its name by utilizing a LoggerNameDecorator such that log messages have the following format. For example if the logfile would be written in a file as of in the context of LoggerFile7FF this mechanism allows to change the logging behavior from

LogLevel |Date (mm-dd |Time (hh:ii:ss.(msec))|Message
DBG |04-09|18:14:44.713|step changed to bootBegin

to

LogLevel |Date (mm-dd |Time (hh:ii:ss.(msec))|Unitname|Message
DBG |04-09|18:14:44.713|Infrastructure|step changed to bootBegin

The Logger class allows to filter messages for a minimum severity level by setting MinimumLevel or MinimumLevelRef property. Logmessages with a Level that is smaller than the level set with this method are ignored.

Constructor

FB_init

METHOD FB_init (
 [input] bInitRetains : BOOL,
 [input] bInCopyCode : BOOL,
 [input] parent : ZCore.IManagedObject) : BOOL

At construction of the LoggerBuffered7FF there are two main initialization parts

Unfortunately the LoggerBuffered7FF function block has no cyclic beahvior and therefore no parent is needed. Here the parent as first parameter is just for consistency that every Logger function block has its same construction and can easily be exchanged with another function block.

Inputs

bInitRetains BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

parent IManagedObject

Usually given as a interface to the ManagedObject that is the parent of this object, here for LoggerBuffered it is not used

Returns

BOOL

Properties

MinimumLevel

PROPERTY MinimumLevel : ZCore.LogLevel

Sets the threshold of logged messages. Logging messages, which have the same severity level or higher will be emitted handled by the logger (others are ignored). The default value for MinimumLevel, which is used when this method is not used to overwrite it, can be parametrized with a library parameter. The MinimumLevel, which is set with this property is for instance only, if the minimum loglevel should be controlled globally for all loggers used in an application, use MinimumLevelRef

Note

Calling this method will unlink the logger instance from the pointer that has been passed with SetLevelRef The Logger uses whatever method was called last.

Property Value

LogLevel

MinimumLevelRef

PROPERTY MinimumLevelRef : REFERENCE TO ZCore.LogLevel

Sets the threshold of logged messages to logLevelRef^. Since the passed value is a reference, it can be changed at any time externally and be shared over several loggers. Logging messages which have the same severity level or higher will be emitted handled by the logger (others are ignored). The default value for logLevel, which is used when this method is not used to overwrite it, can be parametrized with a library parameter.

Note

Calling this method will not effect the logLevel that has been set with MinimumLevel. The Logger uses whatever method was called last.

Property Value

REFERENCE TO LogLevel

Methods

AtDebug

METHOD AtDebug () : ZCore.ILoggerFluentAtLevel

Returns

ILoggerFluentAtLevel

AtError

METHOD AtError () : ZCore.ILoggerFluentAtLevel

Initiates logging a message fluently with log-severity level Error if the severity level applies.

logger.AtError().LogMessage('hello world');

The error level should be used when the application hits an issue preventing one or more functionalities from properly functioning. For instance, if a servo-motor can not reach its desired position or if a sudden pneumatic pressure drop occurs. For more information about this loglevel, see sematext.

Returns

ILoggerFluentAtLevel

AtFatal

METHOD AtFatal () : ZCore.ILoggerFluentAtLevel

Initiates logging a message fluently with log-severity level Fatal if the severity level applies.

logger.AtFatal().LogMessage('hello world');

The error level should be used when the application hits errors that stop the booting process or other hardward related issues (device that is disconnected while using, fieldbus interruptions, ...). For more information about this loglevel, see sematext.

Returns

ILoggerFluentAtLevel

AtInfo

METHOD AtInfo () : ZCore.ILoggerFluentAtLevel

Initiates logging a message fluently with log-severity level Info if the severity level applies.

logger.AtInfo().LogMessage('hello world');

Info is the standard log level and is indicating that something happened, i.e. the application entered a certain state For instance, an operator of your production system starts the automatic sequence and this can be logged as info if it was successfull or not. The information logged using the info log level should be purely informative and not looking into them on a regular basis shouldn’t result in missing any important information. For more information about this loglevel, see sematext.

Returns

ILoggerFluentAtLevel

AtTrace

METHOD AtTrace () : ZCore.ILoggerFluentAtLevel

Initiates logging a message fluently with log-severity level Trace if the severity level applies.

logger.AtTrace().LogMessage('hello world');

Trace is the most fine-grained information only used in rare cases where you need the full visibility of what is happening in your application and inside the third-party libraries that you use. You can expect the trace logging level to be very verbose. You can use it for example to annotate each step in a sequence or extra entries in different if branches. For more information about this loglevel, see sematext.

Returns

ILoggerFluentAtLevel

AtWarning

METHOD AtWarning () : ZCore.ILoggerFluentAtLevel

Initiates logging a message fluently with log-severity level Warning if the severity level applies.

logger.AtWarning().LogMessage('hello world');

A warning indicates that something unexpected happened in the application, a problem, or a situation that might disturb one of the processes. But that doesn’t mean that the application failed or the production system had to be stopped. The warning log level should be used in situations that are unexpected, but the code can continue the work. For example, an electric motor (servo) has two levels for overheating. A warning temperature and a temperature were it is very likely that it will soon get broken. For more information about this loglevel, see sematext.

Returns

ILoggerFluentAtLevel

Buffer

METHOD Buffer (
 [output] indexOfFirst : DINT,
 [output] indexOfLast : DINT) : REFERENCE TO MessageBuffer7FF

Returns a reference to the internally held Message Buffer. This is usefull if there is an implementation of a new logging target which is currently not supported by the Zeugwerk Framework and needs access to the Message Buffer to then afterwards export the messages.

Outputs

indexOfFirst DINT

reference to the head variable of ringbuffer, this one points to the last read entry-index

indexOfLast DINT

reference to the tail variable of ringbuffer, this one points to the next free entry-index

Returns

REFERENCE TO MessageBuffer7FF

Clear

METHOD Clear ()

Clears the logger-internally held ringbuffer immediately no matter how many messages are stored. Usually this is a very efficient way to clean the buffer because it doesn't clear the actual memory that is occupied by the logemessages to zero, but simply sets the indices pointing to the memory to indicate that there are no messages stored.

Debug

METHOD Debug (
 [input] text : ZCore.ZString)

Inputs

text ZString

Desired debug message as ASCII text

Error

METHOD Error (
 [input] text : ZCore.ZString)

Logs a message to the logger with log-severity level Error if the severity level applies.

The error level should be used when the application hits an issue preventing one or more functionalities from properly functioning. For instance, if a servo-motor can not reach its desired position or if a sudden pneumatic pressure drop occurs. For more information about this loglevel, see sematext.

Inputs

text ZString

Desired error message as ASCII text

Fatal

METHOD Fatal (
 [input] text : ZCore.ZString)

Logs a message to the logger with log-severity level Fatal if the severity level applies.

The error level should be used when the application hits errors that stop the booting process or other hardward related issues (device that is disconnected while using, fieldbus interruptions, ...). For more information about this loglevel, see sematext.

Inputs

text ZString

Desired warning message as ASCII text

Info

METHOD Info (
 [input] text : ZCore.ZString)

Logs a message to the logger with log-severity level Info if the severity level applies.

Info is the standard log level and is indicating that something happened, i.e. the application entered a certain state For instance, an operator of your production system starts the automatic sequence and this can be logged as info if it was successfull or not. The information logged using the info log level should be purely informative and not looking into them on a regular basis shouldn’t result in missing any important information. For more information about this loglevel, see sematext.

Inputs

text ZString

Desired information message as ASCII text

LogMessageRef

METHOD LogMessageRef (
 [input] timestamp : ULINT,
 [input] text : REFERENCE TO ZCore.ZString,
 [input] logLevel : ZCore.LogLevel)

Inputs

timestamp ULINT

Unix timestamp of the running PLC target in 1ms resolution

text REFERENCE TO ZString

Desired information message as ASCII text

logLevel LogLevel

LogLevel based on Apache log4j

SetDateTime

METHOD SetDateTime (
 [input] intrf : ZCore.IDateTime)

Sets a Zeugwerk compatible DateTime function block that is used by the predefined logging-methods to automatically fill the timestamp property of a log message. If intrf=0 the timestamp of every message that is logged is 0.

Inputs

intrf IDateTime

Interface to an instantiated Zeugwerk Framework compatible DateTime function block

Trace

METHOD Trace (
 [input] text : ZCore.ZString)

Logs a message to the logger with log-severity level Trace if the severity level applies.

Trace is the most fine-grained information only used in rare cases where you need the full visibility of what is happening in your application and inside the third-party libraries that you use. You can expect the trace logging level to be very verbose. You can use it for example to annotate each step in a sequence or extra entries in different if branches. For more information about this loglevel, see sematext.

Inputs

text ZString

Desired trace message as ASCII text

Warning

METHOD Warning (
 [input] text : ZCore.ZString)

Logs a message to the logger with log-severity level Warning if the severity level applies.

A warning indicates that something unexpected happened in the application, a problem, or a situation that might disturb one of the processes. But that doesn’t mean that the application failed or the production system had to be stopped. The warning log level should be used in situations that are unexpected, but the code can continue the work. For example, an electric motor (servo) has two levels for overheating. A warning temperature and a temperature were it is very likely that it will soon get broken. For more information about this loglevel, see sematext.

Inputs

text ZString

Desired warning message as ASCII text