Log API. More...
Macros | |
#define | EC_LOG_TYPE_REGISTER(name) |
#define | EC_LOG(level, args...) |
#define | EC_VLOG(level, fmt, ap) |
Typedefs | |
typedef int(* | ec_log_t) (int type, enum ec_log_level level, void *opaque, const char *str) |
Enumerations | |
enum | ec_log_level { EC_LOG_EMERG = 0 , EC_LOG_ALERT = 1 , EC_LOG_CRIT = 2 , EC_LOG_ERR = 3 , EC_LOG_WARNING = 4 , EC_LOG_NOTICE = 5 , EC_LOG_INFO = 6 , EC_LOG_DEBUG = 7 } |
Functions | |
int | ec_log_fct_register (ec_log_t usr_log, void *opaque) |
int | ec_log_type_register (const char *name) |
const char * | ec_log_name (int type) |
int | ec_log (int type, enum ec_log_level level, const char *format,...) __attribute__((format(__printf__ |
int int | ec_vlog (int type, enum ec_log_level level, const char *format, va_list ap) |
int | ec_log_default_cb (int type, enum ec_log_level level, void *opaque, const char *str) |
int | ec_log_level_set (enum ec_log_level level) |
enum ec_log_level | ec_log_level_get (void) |
Log API.
This file provide logging helpers:
#define EC_LOG_TYPE_REGISTER | ( | name | ) |
Register a log type.
This macro defines a function that will be called at startup (using the "constructor" attribute). This function registers the named type passed as argument, and sets a static global variable "ec_log_local_type". This variable is used as the default log type for this file when using EC_LOG() or EC_VLOG().
This macro can be present several times in a file. In this case, the local log type is set to the last registered type.
On error, the function aborts.
name | The name of the log to be registered. |
Definition at line 54 of file ecoli_log.h.
#define EC_LOG | ( | level, | |
args... ) |
Log a formatted string using the local log type.
This macro requires that a log type is previously register with EC_LOG_TYPE_REGISTER() since it uses the "ec_log_local_type" variable.
level | The log level. |
args | The format string, followed by optional arguments. |
Definition at line 171 of file ecoli_log.h.
#define EC_VLOG | ( | level, | |
fmt, | |||
ap ) |
Log a formatted string using the local log type.
This macro requires that a log type is previously register with EC_LOG_TYPE_REGISTER() since it uses the "ec_log_local_type" variable.
level | The log level. |
fmt | The format string. |
ap | The list of arguments. |
Definition at line 189 of file ecoli_log.h.
typedef int(* ec_log_t) (int type, enum ec_log_level level, void *opaque, const char *str) |
User log function type.
It is advised that a user-defined log function drops all messages that are at least as critical as ec_log_level_get(), as done by the default handler.
type | The log type identifier. |
level | The log level. |
opaque | The opaque pointer that was passed to ec_log_fct_register(). |
str | The string to log. |
Definition at line 84 of file ecoli_log.h.
enum ec_log_level |
Definition at line 26 of file ecoli_log.h.
int ec_log_fct_register | ( | ec_log_t | usr_log, |
void * | opaque ) |
Register a user log function.
usr_log | Function pointer that will be invoked for each log call. If the parameter is NULL, ec_log_default_cb() is used. |
opaque | Opaque pointer passed to the log function. |
int ec_log_type_register | ( | const char * | name | ) |
Register a named log type.
Register a new log type, which is identified by its name. The function returns a log identifier associated to the log name. If the name is already registered, the function just returns its identifier.
name | The name of the log type. |
const char * ec_log_name | ( | int | type | ) |
Return the log name associated to the log type identifier.
type | The log type identifier. |
int ec_log | ( | int | type, |
enum ec_log_level | level, | ||
const char * | format, | ||
... ) |
Log a formatted string.
type | The log type identifier. |
level | The log level. |
format | The format string, followed by optional arguments. |
int int ec_vlog | ( | int | type, |
enum ec_log_level | level, | ||
const char * | format, | ||
va_list | ap ) |
Log a formatted string.
type | The log type identifier. |
level | The log level. |
format | The format string. |
ap | The list of arguments. |
int ec_log_default_cb | ( | int | type, |
enum ec_log_level | level, | ||
void * | opaque, | ||
const char * | str ) |
Default log handler.
This is the default log function that is used by the library. By default, it prints all logs whose level is WARNING or more critical. This level can be changed with ec_log_level_set().
type | The log type identifier. |
level | The log level. |
opaque | Unused. |
str | The string to be logged. |
int ec_log_level_set | ( | enum ec_log_level | level | ) |
Set the global log level.
This level is used by the default log handler, ec_log_default_cb(). All messages that are at least as critical as the default level are displayed.
It is advised
level | The log level to be set. |
enum ec_log_level ec_log_level_get | ( | void | ) |
Get the global log level.
This level is used by the default log handler, ec_log_default_cb(). All messages that are at least as critical as the default level are displayed.