log_util.c File Reference

Log utility module implementation file. More...

#include "mcl/mcl_config_setup.h"
#include "log_util.h"
#include "mcl/mcl_log_util.h"
#include "file_util.h"
#include "definitions.h"
#include "memory.h"
#include <stdio.h>
Include dependency graph for log_util.c:

Go to the source code of this file.

Macros

#define LOG_UTIL_MCL_SYSLOG   "mcl_syslog"
 

Functions

static void log_util_default_callback (const zf_log_message *const message, void *user_context)
 
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...
 
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...
 
void mcl_log_util_finalize (void)
 Performs finalizing operations for logging. More...
 
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...
 

Variables

FILE * log_file = NULL
 
mcl_log_util_callback_t user_callback = MCL_NULL
 
E_LOG_OUTPUT log_output_global = E_LOG_OUTPUT_STDERR
 
const char * error_code_strings [MCL_ERROR_CODE_END]
 

Detailed Description

Log utility module implementation file.


Date
Jun 27, 2016

Definition in file log_util.c.

Macro Definition Documentation

#define LOG_UTIL_MCL_SYSLOG   "mcl_syslog"

Definition at line 28 of file log_util.c.

Referenced by mcl_log_util_initialize().

Function Documentation

static void log_util_default_callback ( const zf_log_message *const  message,
void *  user_context 
)
static

Definition at line 133 of file log_util.c.

References E_LOG_OUTPUT_CALLBACK, E_LOG_OUTPUT_FILE, E_LOG_OUTPUT_STDERR, E_LOG_OUTPUT_SYSLOG, file_util_fflush_without_log(), file_util_fwrite_without_log(), log_file, log_output_global, MCL_NULL, and user_callback.

Referenced by mcl_log_util_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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:

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:

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.

Variable Documentation

const char* error_code_strings[MCL_ERROR_CODE_END]

Definition at line 35 of file log_util.c.

Referenced by mcl_log_util_convert_error_code_to_string().

FILE* log_file = NULL