Typedefs | Enumerations | Functions

logger.h File Reference

Simple logging interface. More...

Typedefs

typedef char * LogStr
typedef char LogChar
typedef void(* log_callback )(LogStr)

Enumerations

enum  LogBool { LOGBOOL_FALSE, LOGBOOL_TRUE }
enum  LogReturn {
  LOGRET_OK, LOGRET_LACK_MEM, LOGRET_INVALID_LOG_FILE, LOGRET_SNPRINTF_ERR,
  LOGRET_FILE_LOG_ERR, LOGRET_CONSOLE_LOG_ERR
}

Functions

LogReturn log_init (LogStr filename, LogBool append, log_callback cb)
 Initializes the logging instance.
LogReturn log_setlevel (int level)
 Sets global logging level.
LogReturn log_setlevel_file (int level)
 Sets file logging level.
LogReturn log_setlevel_console (int level)
 Sets console logging level.
LogReturn log_setlevel_cb (int level)
 Sets callback logging level.
LogReturn log_log (int level, const char *filename, const char *funcname, int linenum, LogStr format,...)
 Logs a message.
void log_end (void)
 Closes logging facilities (closes log file if opened).

Detailed Description

Simple logging interface.


Typedef Documentation

typedef void(* log_callback)(LogStr)

Custom callback to log message

typedef char LogChar

Logger char type

typedef char* LogStr

Logger string type


Enumeration Type Documentation

enum LogBool

Logger boolean type

Enumerator:
LOGBOOL_FALSE 
LOGBOOL_TRUE 
enum LogReturn

Logger error codes.

Enumerator:
LOGRET_OK 

Success

LOGRET_LACK_MEM 

Memory allocation failed

LOGRET_INVALID_LOG_FILE 

Invalid log file specified

LOGRET_SNPRINTF_ERR 

Problem formatting string

LOGRET_FILE_LOG_ERR 

Problem logging to file

LOGRET_CONSOLE_LOG_ERR 

Problem logging to console


Function Documentation

LogReturn log_init ( LogStr  filename,
LogBool  append,
log_callback  cb 
)

Initializes the logging instance.

Parameters:
[in] filename (optional) file name to log to, pass in NULL to disable
[in] append set to LOGBOOL_TRUE to append to file rather to write new one
[in] cb sets custom callback for logging strings
LogReturn log_log ( int  level,
const char *  filename,
const char *  funcname,
int  linenum,
LogStr  format,
  ... 
)

Logs a message.

Parameters:
[in] level Level of the message (integer)
[in] filename __FILE__ macro or use a custom string
[in] funcname __FUNCTION__ macro or use a custom string
[in] linenum an integer specifying the line number, or a custom number
[in] format printf formatted format, remaining arguments are treated as print inputs.

See the example case at the bottom of logger.c to see how to wrap this in a macro.

LogReturn log_setlevel ( int  level  ) 

Sets global logging level.

Parameters:
[in] level an integer value. Values lower than this will be pass to specific logging functions. (defaults to 10). Set this to less than lowest level to disable logging for all methods.
LogReturn log_setlevel_cb ( int  level  ) 

Sets callback logging level.

Parameters:
[in] level an integer value. Values lower than this will be logged to callback if it is also lower than global level. (defaults to 100). Set this to less than lowest level to disable logging to callback.
LogReturn log_setlevel_console ( int  level  ) 

Sets console logging level.

Parameters:
[in] level an integer value. Values lower than this will be logged to console if it is also lower than global level. (defaults to 100). Set this to less than lowest level to disable logging to file.
LogReturn log_setlevel_file ( int  level  ) 

Sets file logging level.

Parameters:
[in] level an integer value. Values lower than this will be logged to file if it is also lower than global level. (defaults to 100). Set this to less than lowest level to disable logging to file.