ecoli_log - Man Page

Name

ecoli_log — Log

— Log API.  

Synopsis

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)

Detailed Description

Log API.

This file provide logging helpers:

Macro Definition Documentation

#define EC_LOG_TYPE_REGISTER( name)

Value:

    static int name##_log_type;                 \
    static int ec_log_local_type;                   \
    __attribute__((constructor, used))              \
    static void ec_log_register_##name(void)            \
    {                               \
        ec_log_local_type = ec_log_type_register(#name);    \
        ec_assert_print(ec_log_local_type >= 0,         \
                "cannot register log type.\n");      \
        name##_log_type = ec_log_local_type;            \
    }

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.

Parameters

name The name of the log to be registered.

Definition at line 54 of file ecoli_log.h.

#define EC_LOG( level,  args...)

Value:

ec_log(ec_log_local_type, 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.

Parameters

level The log level.
args The format string, followed by optional arguments.

Returns

0 on success, -1 on error (errno is set).

Definition at line 171 of file ecoli_log.h.

#define EC_VLOG( level,  fmt,  ap)

Value:

ec_vlog(ec_log_local_type, 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.

Parameters

level The log level.
fmt The format string.
ap The list of arguments.

Returns

0 on success, -1 on error (errno is set).

Definition at line 189 of file ecoli_log.h.

Typedef Documentation

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.

Parameters

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.

Returns

0 on success, -1 on error (errno is set).

Definition at line 84 of file ecoli_log.h.

Enumeration Type Documentation

enum ec_log_level

Definition at line 26 of file ecoli_log.h.

Function Documentation

int ec_log_fct_register (ec_log_t usr_log, void * opaque)

Register a user log function.

Parameters

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.

Returns

0 on success, -1 on error (errno is set).

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.

Parameters

name The name of the log type.

Returns

The log type identifier on success (positive or zero), -1 on error (errno is set).

const char * ec_log_name (int type)

Return the log name associated to the log type identifier.

Parameters

type The log type identifier.

Returns

The name associated to the log type, or 'unknown'. It always return a valid string (never NULL).

int ec_log (int type, enum ec_log_level level, const char * format,  ...)

Log a formatted string.

Parameters

type The log type identifier.
level The log level.
format The format string, followed by optional arguments.

Returns

0 on success, -1 on error (errno is set).

int int ec_vlog (int type, enum ec_log_level level, const char * format, va_list ap)

Log a formatted string.

Parameters

type The log type identifier.
level The log level.
format The format string.
ap The list of arguments.

Returns

0 on success, -1 on error (errno is set).

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().

Parameters

type The log type identifier.
level The log level.
opaque Unused.
str The string to be logged.

Returns

0 on success, -1 on error (errno is set).

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

Parameters

level The log level to be set.

Returns

0 on success, -1 on error.

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.

Returns

The current global log level

Author

Generated automatically by Doxygen for Libecoli from the source code.

Referenced By

The man pages ec_log(3), EC_LOG(3), ec_log_default_cb(3), ec_log_fct_register(3), ec_log_level(3), ec_log_level_get(3), ec_log_level_set(3), ec_log_name(3), ec_log_t(3), ec_log_type_register(3), EC_LOG_TYPE_REGISTER(3), ec_vlog(3) and EC_VLOG(3) are aliases of ecoli_log(3).

Version 0.3.0 Libecoli