S2OPC OPCUA Toolkit
Data Structures | Typedefs | Enumerations | Functions
sopc_log_manager.h File Reference

Provide circular logging. More...

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "sopc_circular_log_file.h"

Go to the source code of this file.

Data Structures

struct  SOPC_LogSystem_File_Configuration
 structure containing the file log configuration More...
 
struct  SOPC_LogSystem_User_Configuration
 structure containing the user system log configuration More...
 
union  SOPC_Log_SystemConfiguration
 Provides possible logging configurations. More...
 
struct  SOPC_Log_Configuration
 Defines logging configuration. More...
 

Typedefs

typedef struct SOPC_Log_Instance SOPC_Log_Instance
 
typedef void SOPC_Log_UserDoLog(const char *timestampUtc, const char *category, const SOPC_Log_Level level, const char *const line)
 Log event callback. More...
 
typedef struct SOPC_LogSystem_File_Configuration SOPC_LogSystem_File_Configuration
 structure containing the file log configuration More...
 
typedef struct SOPC_LogSystem_User_Configuration SOPC_LogSystem_User_Configuration
 structure containing the user system log configuration More...
 
typedef enum SOPC_Log_System SOPC_Log_System
 log system discriminant More...
 
typedef union SOPC_Log_SystemConfiguration SOPC_Log_SystemConfiguration
 Provides possible logging configurations. More...
 
typedef struct SOPC_Log_Configuration SOPC_Log_Configuration
 Defines logging configuration. More...
 

Enumerations

enum  SOPC_Log_Level {
  SOPC_LOG_LEVEL_ERROR = 0, SOPC_LOG_LEVEL_WARNING = 1, SOPC_LOG_LEVEL_INFO = 2, SOPC_LOG_LEVEL_DEBUG = 3,
  SOPC_LOG_LEVEL_ERROR = 0, SOPC_LOG_LEVEL_WARNING = 1, SOPC_LOG_LEVEL_INFO = 2, SOPC_LOG_LEVEL_DEBUG = 3
}
 
enum  SOPC_Log_System { SOPC_LOG_SYSTEM_FILE, SOPC_LOG_SYSTEM_USER, SOPC_LOG_SYSTEM_NO_LOG }
 log system discriminant More...
 

Functions

SOPC_Log_InstanceSOPC_Log_CreateFileInstance (const SOPC_CircularLogFile_Configuration *pConf, const char *category)
 Creates a new log file and log instance and prints the starting timestamp. More...
 
SOPC_Log_InstanceSOPC_Log_CreateUserInstance (const char *category, SOPC_Log_UserDoLog *logCallback)
 Creates a new log instance for user mode. More...
 
SOPC_Log_InstanceSOPC_Log_CreateInstanceAssociation (SOPC_Log_Instance *pLogInst, const char *category)
 Creates a new log instance using the same log file than existing log instance and prints the starting timestamp. It provides the way to have several categories with different levels of log in the same log file. More...
 
bool SOPC_Log_SetLogLevel (SOPC_Log_Instance *pLogInst, SOPC_Log_Level level)
 
SOPC_Log_Level SOPC_Log_GetLogLevel (SOPC_Log_Instance *pLogInst)
 getter for the log level of an instance More...
 
bool SOPC_Log_SetConsoleOutput (SOPC_Log_Instance *pLogInst, bool activate)
 Activates the console output for logged traces (same active level as log file) More...
 
char * SOPC_Log_GetCurrentFilename (const SOPC_Log_Instance *pLogInst)
 Get the name of the current log file. More...
 
void SOPC_Log_Trace (SOPC_Log_Instance *pLogInst, SOPC_Log_Level level, const char *format,...)
 Logs a trace with the given level. More...
 
void SOPC_Log_VTrace (SOPC_Log_Instance *pLogInst, SOPC_Log_Level level, const char *format, va_list args)
 Logs a trace with the given level. More...
 
void SOPC_Log_ClearInstance (SOPC_Log_Instance **ppLogInst)
 Stops allowing to log traces in the given log instance. Log file is closed when last log instance is stopped. More...
 

Detailed Description

Provide circular logging.

A log manager providing circular logging, multiple logging categories and levels with thread-safe accesses.

Typedef Documentation

◆ SOPC_Log_Instance

◆ SOPC_Log_UserDoLog

typedef void SOPC_Log_UserDoLog(const char *timestampUtc, const char *category, const SOPC_Log_Level level, const char *const line)

Log event callback.

Parameters
[in]timestampUtcString pointer containing the event timestamp (UTC time)
[in]categoryString pointer containing the category. Can be NULL, when not related to any category,
[in]levelThe level of the log (Already filtered out if below current log level),
[in]lineNon-null string pointer, containing the full log line, including NULL-terminating character but excluding any newline character, so that it can be specificly defined for each platform. The line has already been filtered (level) and formatted by logger core. In all cases, the line is truncated to SOPC_Log_UserMaxLogLen characters.

◆ SOPC_LogSystem_File_Configuration

structure containing the file log configuration

◆ SOPC_LogSystem_User_Configuration

structure containing the user system log configuration

◆ SOPC_Log_System

log system discriminant

◆ SOPC_Log_SystemConfiguration

Provides possible logging configurations.

◆ SOPC_Log_Configuration

Defines logging configuration.

Enumeration Type Documentation

◆ SOPC_Log_Level

Enumerator
SOPC_LOG_LEVEL_ERROR 
SOPC_LOG_LEVEL_WARNING 
SOPC_LOG_LEVEL_INFO 
SOPC_LOG_LEVEL_DEBUG 
SOPC_LOG_LEVEL_ERROR 
SOPC_LOG_LEVEL_WARNING 
SOPC_LOG_LEVEL_INFO 
SOPC_LOG_LEVEL_DEBUG 

◆ SOPC_Log_System

log system discriminant

Enumerator
SOPC_LOG_SYSTEM_FILE 

file system logger

SOPC_LOG_SYSTEM_USER 

user-implemented system logger

SOPC_LOG_SYSTEM_NO_LOG 

no system logger

Function Documentation

◆ SOPC_Log_CreateFileInstance()

SOPC_Log_Instance* SOPC_Log_CreateFileInstance ( const SOPC_CircularLogFile_Configuration pConf,
const char *  category 
)

Creates a new log file and log instance and prints the starting timestamp.

Parameters
pConfA non-NULL pointer to the file instance configuration
categoryA category name if the log file is used for several categories or NULL. Truncated if more than 9 characters.
Returns
The log instance to be used to add traces

◆ SOPC_Log_CreateUserInstance()

SOPC_Log_Instance* SOPC_Log_CreateUserInstance ( const char *  category,
SOPC_Log_UserDoLog logCallback 
)

Creates a new log instance for user mode.

Parameters
categoryA category name if the log file is used for several categories or NULL. Truncated if more than 9 characters.
logCallbackThe user logging callback. If set to NULL, no user event is called.
Returns
The log instance to be used to add traces

◆ SOPC_Log_CreateInstanceAssociation()

SOPC_Log_Instance* SOPC_Log_CreateInstanceAssociation ( SOPC_Log_Instance pLogInst,
const char *  category 
)

Creates a new log instance using the same log file than existing log instance and prints the starting timestamp. It provides the way to have several categories with different levels of log in the same log file.

Parameters
pLogInstAn existing log instance used to print in the same log file
categoryCategory for the new log instance in the log file (should be unique in log file)
Returns
The log instance to be used to add traces
Note
The new instance must always be cleared before the parent reference instance.

◆ SOPC_Log_SetLogLevel()

bool SOPC_Log_SetLogLevel ( SOPC_Log_Instance pLogInst,
SOPC_Log_Level  level 
)

◆ SOPC_Log_GetLogLevel()

SOPC_Log_Level SOPC_Log_GetLogLevel ( SOPC_Log_Instance pLogInst)

getter for the log level of an instance

Parameters
pLogInstAn existing log instance
Returns
the log level for the specified instance

◆ SOPC_Log_SetConsoleOutput()

bool SOPC_Log_SetConsoleOutput ( SOPC_Log_Instance pLogInst,
bool  activate 
)

Activates the console output for logged traces (same active level as log file)

Parameters
pLogInstAn existing log instance
activateFlag to activate / deactivate the console output

◆ SOPC_Log_GetCurrentFilename()

char* SOPC_Log_GetCurrentFilename ( const SOPC_Log_Instance pLogInst)

Get the name of the current log file.

Parameters
pLogInstAn existing log instance
Returns
Name of current output log file or NULL if not applicable. The returned value must be deallocated be caller.

◆ SOPC_Log_Trace()

void SOPC_Log_Trace ( SOPC_Log_Instance pLogInst,
SOPC_Log_Level  level,
const char *  format,
  ... 
)

Logs a trace with the given level.

Parameters
pLogInstAn existing log instance already started
levelThe log level corresponding to the given trace
formatString specifying how subsequent arguments are converted for output

◆ SOPC_Log_VTrace()

void SOPC_Log_VTrace ( SOPC_Log_Instance pLogInst,
SOPC_Log_Level  level,
const char *  format,
va_list  args 
)

Logs a trace with the given level.

Parameters
pLogInstAn existing log instance already started
levelThe log level corresponding to the given trace
formatString specifying how subsequent arguments are converted for output
argsArguments used by the string specifying the output

◆ SOPC_Log_ClearInstance()

void SOPC_Log_ClearInstance ( SOPC_Log_Instance **  ppLogInst)

Stops allowing to log traces in the given log instance. Log file is closed when last log instance is stopped.

Parameters
ppLogInstAn existing log instance already started. Pointer set to NULL after call.