Logger
- Namespace
- ZAux
- Implements
Logger is an abstract class that allows to write simple logs to various targets (file, syslog, eventlog or the visual studio log window, ...). The Zeugwerk Framework includes various specializations, including
- LoggerFile7FF: File logger that writes an ASCII Text file to a hard disk with advanced features such as file rolling. This file can be viewed while the PLC is running, just make sure not to lock the file while your PLC is running and writing logs.
- LoggerBuffered: This implementation can be used to extract the entered log entries out of the buffer by external applications (i.e. a HMI)
The generic structure of this implementation allows one to implement various other targets, such as MQTT Servers, Syslog, ...
A single log message has the following properties
- LogLevel: Severity of a message
- Timestamp: Timestamp that contains information about when a message was logged written as a unix standardized timestamp in 1ms resolution
- Message: String that contains the actual information that should be logged.
And can be written 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. In the context of LoggerFile7FF this 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.
FUNCTION_BLOCK ABSTRACT Logger IMPLEMENTS ZCore.ILogger, ZCore.ILoggerBase, ZCore.ILoggerImperativeApi, ZCore.ILoggerFluentApi
Properties
MinimumLevel
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 MinimumLevel : ZCore.LogLevel
Property Value
MinimumLevelRef
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 MinimumLevelRef : REFERENCE TO ZCore.LogLevel
Property Value
- REFERENCE TO LogLevel
Methods
AtDebug
Initiates logging a message fluently with log-severity level Debug if the severity level applies.
logger.AtDebug().LogMessage('hello world');
A Debug message is less granular compared to the trace level, but it is more than you will need in everyday use. The debug log level should be used for information that may be needed for diagnosing issues and troubleshooting or when running an application in a test environment for the purpose of making sure everything is running correctly. For more information about this loglevel, see sematext.
METHOD AtDebug () : ZCore.ILoggerFluentAtLevel
Returns
AtError
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.
METHOD AtError () : ZCore.ILoggerFluentAtLevel
Returns
AtFatal
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.
METHOD AtFatal () : ZCore.ILoggerFluentAtLevel
Returns
AtInfo
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.
METHOD AtInfo () : ZCore.ILoggerFluentAtLevel
Returns
AtTrace
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.
METHOD AtTrace () : ZCore.ILoggerFluentAtLevel
Returns
AtWarning
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.
METHOD AtWarning () : ZCore.ILoggerFluentAtLevel
Returns
Debug
Logs a message to the logger with log-severity level Debug if the severity level applies.
A Debug message is less granular compared to the trace level, but it is more than you will need in everyday use. The debug log level should be used for information that may be needed for diagnosing issues and troubleshooting or when running an application in a test environment for the purpose of making sure everything is running correctly. For more information about this loglevel, see sematext.
METHOD Debug (
text : ZCore.ZString)
Inputs
text
ZStringDesired debug message as ASCII text
Error
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.
METHOD Error (
text : ZCore.ZString)
Inputs
text
ZStringDesired error message as ASCII text
Fatal
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.
METHOD Fatal (
text : ZCore.ZString)
Inputs
text
ZStringDesired warning message as ASCII text
Info
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.
METHOD Info (
text : ZCore.ZString)
Inputs
text
ZStringDesired information message as ASCII text
LogMessageRef
This method allows to set every single property of a log message manually. Usually this method should not be used in an application, use one of the specialized methods instead (i.e. Debug, Trace)
The timestamp
property is overwritten by the actual timestamp if timestamp=0
.
METHOD LogMessageRef (
timestamp : ULINT,
text : REFERENCE TO ZCore.ZString,
logLevel : ZCore.LogLevel)
Inputs
timestamp
ULINTUnix timestamp of the running PLC target in 1ms resolution
text
REFERENCE TO ZStringDesired information message as ASCII text
logLevel
LogLevelLogLevel based on Apache log4j
Trace
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.
METHOD Trace (
text : ZCore.ZString)
Inputs
text
ZStringDesired trace message as ASCII text
Warning
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.
METHOD Warning (
text : ZCore.ZString)
Inputs
text
ZStringDesired warning message as ASCII text