S2OPC OPCUA Toolkit
sopc_log_manager.h
Go to the documentation of this file.
1 /*
2  * Licensed to Systerel under one or more contributor license
3  * agreements. See the NOTICE file distributed with this work
4  * for additional information regarding copyright ownership.
5  * Systerel licenses this file to you under the Apache
6  * License, Version 2.0 (the "License"); you may not use this
7  * file except in compliance with the License. You may obtain
8  * a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
26 #ifndef SOPC_LOG_MANAGER_H_
27 #define SOPC_LOG_MANAGER_H_
28 
29 #include <stdarg.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32 
34 
35 typedef enum
36 {
42 
53 typedef void SOPC_Log_UserDoLog(const char* category, const char* const line);
54 
59 {
60  const char* logDirPath;
61  uint32_t logMaxBytes;
62  uint16_t logMaxFiles;
64 
69 {
72 
76 typedef enum SOPC_Log_System
77 {
82 
87 {
91 
95 typedef struct SOPC_Log_Configuration
96 {
101 
109 
127  const char* logDirPath,
128  const char* logFileName,
129  const char* category,
130  uint32_t maxBytes, // New file created when maxBytes reached (after printing latest trace)
131  uint16_t maxFiles); // Old logs overwritten when maxFiles reached
132 
133 /*
134  * \brief Creates a new log instance for user mode
135  *
136  * \param category A category name if the log file is used for several categories or NULL. Truncated if more than 9
137  * characters.
138  * \param logCallback The user logging callback. If set to NULL, no user event is called.
139  *
140  * \return The log instance to be used to add traces
141  * */
143 
144 /*
145  * \brief Creates a new log instance using the same log file than existing log instance and prints the starting
146  * timestamp. It provides the way to have several categories with different levels of log in the same log file.
147  *
148  * \param pLogInst An existing log instance used to print in the same log file
149  * \param category Category for the new log instance in the log file (should be unique in log file)
150  *
151  * \return The log instance to be used to add traces
152  */
154 
155 /*
156  * \brief Defines the active log level for the given log instance (default: ERROR):
157  * - ERROR: display only ERROR level
158  * - WARNING: display ERROR + WARNING levels
159  * - INFO: display ERROR + WARNING + INFO levels
160  * - DEBUG: display ERROR + WARNING + INFO + DEBUG levels
161  *
162  * \param pLogInst An existing log instance
163  * \param level The level to be activated for the log instance
164  */
166 
167 /*
168  * \brief getter for the log level of an instance
169  *
170  * \param pLogInst An existing log instance
171  *
172  * \return the log level for the specified instance
173  */
175 
176 /*
177  * \brief Activates the console output for logged traces (same active level as log file)
178  *
179  * \param pLogInst An existing log instance
180  * \param activate Flag to activate / deactivate the console output
181  */
182 bool SOPC_Log_SetConsoleOutput(SOPC_Log_Instance* pLogInst, bool activate);
183 
184 /*
185  * \brief Returns the file path prefix for the given log instance.
186  * It complies with the following format: <logDirPath><startExecutionDate><logFileName>_
187  * - <logDirPath>: the path provided to SOPC_Log_CreateInstance
188  * - <startExecutionDate>: the starting execution date set by SOPC_Log_Initialize (or UNINIT_LOG if not initialized)
189  * - <logFileName>: the log file name provided to SOPC_Log_CreateInstance
190  * Note: the complete file path is then the returned prefix followed by <NNNNN>.log with N digits starting to 00001
191  *
192  * \param pLogInst An existing log instance
193  * \return The generic file path prefix of the log files for the given instance (to be deallocated by caller)
194  */
196 
197 /*
198  * \brief Logs a trace with the given level
199  *
200  * \param pLogInst An existing log instance already started
201  * \param level The log level corresponding to the given trace
202  * \param format String specifying how subsequent arguments are converted for output
203  */
204 void SOPC_Log_Trace(SOPC_Log_Instance* pLogInst, SOPC_Log_Level level, const char* format, ...);
205 
206 /*
207  * \brief Logs a trace with the given level
208  *
209  * \param pLogInst An existing log instance already started
210  * \param level The log level corresponding to the given trace
211  * \param format String specifying how subsequent arguments are converted for output
212  * \param args Arguments used by the string specifying the output
213  */
214 void SOPC_Log_VTrace(SOPC_Log_Instance* pLogInst, SOPC_Log_Level level, const char* format, va_list args);
215 
216 /*
217  * \brief Stops allowing to log traces in the given log instance. Log file is closed when last log instance is stopped.
218  *
219  * \param ppLogInst An existing log instance already started. Pointer set to NULL after call.
220  */
222 
223 /*
224  * \brief Clears the logger manager: clear unique file name prefix for execution
225  * */
226 void SOPC_Log_Clear(void);
227 
228 #endif /* SOPC_LOG_MANAGER_H_ */
SOPC_Log_UserDoLog
void SOPC_Log_UserDoLog(const char *category, const char *const line)
Log event callback.
Definition: sopc_log_manager.h:53
SOPC_LogSystem_File_Configuration
struct SOPC_LogSystem_File_Configuration SOPC_LogSystem_File_Configuration
structure containing the file system log configuration
SOPC_Log_SystemConfiguration::fileSystemLogConfig
SOPC_LogSystem_File_Configuration fileSystemLogConfig
Definition: sopc_log_manager.h:88
SOPC_Log_CreateInstanceAssociation
SOPC_Log_Instance * SOPC_Log_CreateInstanceAssociation(SOPC_Log_Instance *pLogInst, const char *category)
SOPC_LogSystem_File_Configuration::logDirPath
const char * logDirPath
Definition: sopc_log_manager.h:60
SOPC_Log_Trace
void SOPC_Log_Trace(SOPC_Log_Instance *pLogInst, SOPC_Log_Level level, const char *format,...)
SOPC_Log_GetLogLevel
SOPC_Log_Level SOPC_Log_GetLogLevel(SOPC_Log_Instance *pLogInst)
SOPC_Log_Configuration
struct SOPC_Log_Configuration SOPC_Log_Configuration
Defines logging configuration.
SOPC_Log_System
SOPC_Log_System
log system discriminant
Definition: sopc_log_manager.h:77
SOPC_Log_Level
SOPC_Log_Level
Definition: sopc_log_manager.h:36
SOPC_Log_Configuration
Defines logging configuration.
Definition: sopc_log_manager.h:96
SOPC_Log_GetFilePathPrefix
char * SOPC_Log_GetFilePathPrefix(SOPC_Log_Instance *pLogInst)
SOPC_LOG_LEVEL_INFO
@ SOPC_LOG_LEVEL_INFO
Definition: sopc_log_manager.h:39
SOPC_LogSystem_File_Configuration
structure containing the file system log configuration
Definition: sopc_log_manager.h:59
SOPC_LOG_LEVEL_DEBUG
@ SOPC_LOG_LEVEL_DEBUG
Definition: sopc_log_manager.h:40
SOPC_Log_CreateFileInstance
SOPC_Log_Instance * SOPC_Log_CreateFileInstance(const char *logDirPath, const char *logFileName, const char *category, uint32_t maxBytes, uint16_t maxFiles)
Creates a new log file and log instance and prints the starting timestamp.
SOPC_Log_ClearInstance
void SOPC_Log_ClearInstance(SOPC_Log_Instance **ppLogInst)
SOPC_LogSystem_User_Configuration::doLog
SOPC_Log_UserDoLog * doLog
Definition: sopc_log_manager.h:70
SOPC_Log_Level
SOPC_Log_Level
Definition: libs2opc_client.h:79
SOPC_LogSystem_File_Configuration::logMaxFiles
uint16_t logMaxFiles
Definition: sopc_log_manager.h:62
SOPC_Log_Instance
struct SOPC_Log_Instance SOPC_Log_Instance
Definition: sopc_log_manager.h:33
SOPC_LOG_SYSTEM_FILE
@ SOPC_LOG_SYSTEM_FILE
Definition: sopc_log_manager.h:78
SOPC_LogSystem_File_Configuration::logMaxBytes
uint32_t logMaxBytes
Definition: sopc_log_manager.h:61
SOPC_LOG_LEVEL_WARNING
@ SOPC_LOG_LEVEL_WARNING
Definition: sopc_log_manager.h:38
SOPC_Log_SetLogLevel
bool SOPC_Log_SetLogLevel(SOPC_Log_Instance *pLogInst, SOPC_Log_Level level)
SOPC_Log_Configuration::logSystem
SOPC_Log_System logSystem
Definition: sopc_log_manager.h:98
SOPC_Log_Clear
void SOPC_Log_Clear(void)
SOPC_Log_Configuration::logLevel
SOPC_Log_Level logLevel
Definition: sopc_log_manager.h:97
SOPC_Log_Configuration::logSysConfig
SOPC_Log_SystemConfiguration logSysConfig
Definition: sopc_log_manager.h:99
SOPC_Log_SystemConfiguration
Provides possible logging configurations.
Definition: sopc_log_manager.h:87
SOPC_Log_VTrace
void SOPC_Log_VTrace(SOPC_Log_Instance *pLogInst, SOPC_Log_Level level, const char *format, va_list args)
SOPC_LOG_SYSTEM_NO_LOG
@ SOPC_LOG_SYSTEM_NO_LOG
Definition: sopc_log_manager.h:80
SOPC_LogSystem_User_Configuration
structure containing the user system log configuration
Definition: sopc_log_manager.h:69
SOPC_Log_Initialize
void SOPC_Log_Initialize(void)
Initializes the logger manager: generate unique file name prefix for execution. This prefix is only r...
SOPC_Log_SystemConfiguration::userSystemLogConfig
SOPC_LogSystem_User_Configuration userSystemLogConfig
Definition: sopc_log_manager.h:89
SOPC_Log_CreateUserInstance
SOPC_Log_Instance * SOPC_Log_CreateUserInstance(const char *category, SOPC_Log_UserDoLog *logCallback)
SOPC_LOG_LEVEL_ERROR
@ SOPC_LOG_LEVEL_ERROR
Definition: sopc_log_manager.h:37
SOPC_LogSystem_User_Configuration
struct SOPC_LogSystem_User_Configuration SOPC_LogSystem_User_Configuration
structure containing the user system log configuration
SOPC_LOG_SYSTEM_USER
@ SOPC_LOG_SYSTEM_USER
Definition: sopc_log_manager.h:79
SOPC_Log_SystemConfiguration
union SOPC_Log_SystemConfiguration SOPC_Log_SystemConfiguration
Provides possible logging configurations.
SOPC_Log_SetConsoleOutput
bool SOPC_Log_SetConsoleOutput(SOPC_Log_Instance *pLogInst, bool activate)