mcl_log_util.h File Reference

Log utility module interface header file. More...

#include "mcl/mcl_common.h"
#include <stdarg.h>
Include dependency graph for mcl_log_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* mcl_log_util_callback_t) (int log_level, const char *tag, const char *message, void *user_context)
 Log util callback function definition. More...
 

Enumerations

enum  E_LOG_OUTPUT {
  E_LOG_OUTPUT_FILE, E_LOG_OUTPUT_CALLBACK, E_LOG_OUTPUT_SYSLOG, E_LOG_OUTPUT_STDERR,
  E_LOG_OUTPUT_NULL
}
 MCL Log output definitions. More...
 

Functions

MCL_EXPORT E_MCL_ERROR_CODE mcl_log_util_set_output_level (const int log_level)
 Sets the global output level. The output level is used during runtime check. No logs are written if given log level is less than this output level. More...
 
MCL_EXPORT E_MCL_ERROR_CODE mcl_log_util_initialize (E_LOG_OUTPUT log_output,...)
 This function initializes logging where output channel is set and configured via variable arguments. More...
 
MCL_EXPORT void mcl_log_util_finalize (void)
 Performs finalizing operations for logging. More...
 
MCL_EXPORT const char * mcl_log_util_convert_error_code_to_string (E_MCL_ERROR_CODE error_code)
 This function converts the given error code to its string value. More...
 

Detailed Description

Log utility module interface header file.


Date
Jan 30, 2017 This utility module defines macros and functions for logging purposes.

Definition in file mcl_log_util.h.

Typedef Documentation

typedef void(* mcl_log_util_callback_t) (int log_level, const char *tag, const char *message, void *user_context)

Log util callback function definition.

User's callback can be used with mcl_log_util_callback_t. Given parameters are log_level: Log level of the message, tag: Associated tag, message: The log message formatted as : Timestamp | PID | Thread ID | Level | Tag | module.function | line | message and user_context: User's own context.

Definition at line 46 of file mcl_log_util.h.

Enumeration Type Documentation

MCL Log output definitions.

Enumerator
E_LOG_OUTPUT_FILE 

Log output channel is file.

E_LOG_OUTPUT_CALLBACK 

Log output channel is callback.

E_LOG_OUTPUT_SYSLOG 

Log output channel is syslog.

E_LOG_OUTPUT_STDERR 

Log output channel is stderr.

E_LOG_OUTPUT_NULL 

No log output chosen.

Definition at line 30 of file mcl_log_util.h.

Function Documentation

MCL_EXPORT const char* mcl_log_util_convert_error_code_to_string ( E_MCL_ERROR_CODE  error_code)

This function converts the given error code to its string value.

Parameters
[in]error_codeError code to convert to string.
Returns
Converted error code in string, NULL if error_code is invalid. It should not be freed, because its owner is MCL.

Definition at line 250 of file log_util.c.

References DEBUG_ENTRY, DEBUG_LEAVE, error_code_strings, MCL_ERROR, MCL_ERROR_CODE_END, MCL_NULL, and MCL_OK.

MCL_EXPORT void mcl_log_util_finalize ( void  )

Performs finalizing operations for logging.

Warning
  • If during initialization a log file is opened, this function must be called in order to close the log file.
  • If syslog has been initialized, this function must be called in order to close output to syslog.

Definition at line 230 of file log_util.c.

References E_LOG_OUTPUT_CALLBACK, E_LOG_OUTPUT_FILE, E_LOG_OUTPUT_NULL, E_LOG_OUTPUT_SYSLOG, file_util_fclose_without_log(), log_file, log_output_global, MCL_NULL, and user_callback.

Here is the call graph for this function:

MCL_EXPORT E_MCL_ERROR_CODE mcl_log_util_initialize ( E_LOG_OUTPUT  log_output,
  ... 
)

This function initializes logging where output channel is set and configured via variable arguments.

Output channel and related variable arguments are as following:

  • if log_output = E_LOG_OUTPUT_FILE, second argument has to be the file name.
    Note
    File name can be a full path. If only name is provided, the log file will be created relative to the executable's working directory.
    Given log file is opened for write operation. Any older log messages will be deleted.
    Given log file remains open until mcl_log_util_finalize has been called.
  • if log_output = E_LOG_OUTPUT_CALLBACK, second argument is mcl_log_util_callback_t and third argument is void *user_context
  • if log_output = E_LOG_OUTPUT_SYSLOG, no additional argument is required.
  • if log_output = E_LOG_OUTPUT_STDERR, no additional argument is required.

After initialization any log messages are printed to the chosen output channel.

Parameters
[in]log_outputSelects the desired output channel.

Definition at line 185 of file log_util.c.

References E_LOG_OUTPUT_CALLBACK, E_LOG_OUTPUT_FILE, E_LOG_OUTPUT_SYSLOG, file_util_fopen_without_log(), log_file, log_output_global, log_util_default_callback(), LOG_UTIL_MCL_SYSLOG, MCL_FILE_CANNOT_BE_OPENED, MCL_INVALID_PARAMETER, MCL_NULL, MCL_OK, and user_callback.

Here is the call graph for this function:

MCL_EXPORT E_MCL_ERROR_CODE mcl_log_util_set_output_level ( const int  log_level)

Sets the global output level. The output level is used during runtime check. No logs are written if given log level is less than this output level.

Parameters
[in]log_levelThe output level to set with. Following log levels can be set.
  • MCL_LOG_UTIL_LEVEL_VERBOSE. //!< All other events.
  • MCL_LOG_UTIL_LEVEL_DEBUG. //!< Minimal set of events that could help to reconstruct the execution path.
  • MCL_LOG_UTIL_LEVEL_INFO. //!< Happened significant life cycle event or major state transition.
  • MCL_LOG_UTIL_LEVEL_WARN. //!< happened something that usually should not happen and significantly changes application behavior for some period of time.
  • MCL_LOG_UTIL_LEVEL_ERROR. //!< happened something possible, but highly unexpected. The process is able to recover and continue execution.
  • MCL_LOG_UTIL_LEVEL_FATAL. //!< Happened something impossible and absolutely unexpected. Process can't continue and must be terminated.
  • MCL_LOG_UTIL_LEVEL_NONE. //!< None.

Definition at line 174 of file log_util.c.

References LOG_UTIL_LEVEL_FATAL, LOG_UTIL_LEVEL_NONE, LOG_UTIL_LEVEL_VERBOSE, MCL_INVALID_LOG_LEVEL, and MCL_OK.