5.3. Logging

The EC-Monitor offers a logging interface for a more detailed analysis of application errors, problems in the EtherCAT network and for diagnosing internal processes. The log messages are passed from the EC-Monitor to the application via the callback EC_T_LOG_PARMS::pfLogMsg given at EC_T_MONITOR_INIT_PARMS::LogParms.

typedef EC_T_DWORD (*EC_PF_LOGMSGHK)(struct _EC_T_LOG_CONTEXT *pContext, EC_T_DWORD dwLogMsgSeverity, const EC_T_CHAR *szFormat, ...)

The level of detail of the logging output can be set via EC_T_LOG_PARMS::dwLogLevel. The log levels are firmly defined:

EC_LOG_LEVELS

  • EC_LOG_LEVEL_SILENT

  • EC_LOG_LEVEL_ANY

  • EC_LOG_LEVEL_CRITICAL

  • EC_LOG_LEVEL_ERROR

  • EC_LOG_LEVEL_WARNING

  • EC_LOG_LEVEL_INFO

  • EC_LOG_LEVEL_INFO_API

  • EC_LOG_LEVEL_VERBOSE

  • EC_LOG_LEVEL_VERBOSE_ACYC

  • EC_LOG_LEVEL_VERBOSE_CYC

  • EC_LOG_LEVEL_UNDEFINED

For performance reasons, the log messages are automatically filtered based on the log level and then passed to the callback.

Example

The EcMonitorDemo examples demonstrate how log messages can be processed by the application, see Examples/Common/EcLogging.cpp. The messages processed by EcLogging.cpp are of different types, e.g. EC-Monitor log messages and application messages are logged to the console and/or files. Identical messages are skipped automatically by default.

Note

With some operating systems, logging in files is deactivated, e.g. because a file system is not available.

The verbosity of the EcMonitorDemo is specified as a -v command line parameter. It is used to determine the log level of the application, see EcDemoMain.cpp. EcLogging.cpp has various parameters beside the log level, like Roll Over setting, log task priority, CPU affinity, log buffer size and etc.