universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: ucx: /home/mike/workspace/c/ucx/src/ucx/logging.h File Reference universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
ucx universe@390:
universe@390:
UAP Common Extensions
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390:
universe@390: universe@390:
universe@390: universe@390: universe@390:
universe@390:
universe@390:
universe@390: Data Structures | universe@390: Macros | universe@390: Functions
universe@390:
universe@390:
logging.h File Reference
universe@390:
universe@390:
universe@390: universe@390:

Logging API. universe@390: More...

universe@390:
#include "ucx.h"
universe@390: #include "map.h"
universe@390: #include "string.h"
universe@390: #include <stdio.h>
universe@390:
universe@390:

Go to the source code of this file.

universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Data Structures

struct  UcxLogger
 The UCX Logger object. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Macros

#define UCX_LOGGER_ERROR   0x00
 Log level for error messages. More...
 
#define UCX_LOGGER_WARN   0x10
 Log level for warning messages. More...
 
#define UCX_LOGGER_INFO   0x20
 Log level for information messages. More...
 
#define UCX_LOGGER_DEBUG   0x30
 Log level for debug messages. More...
 
#define UCX_LOGGER_TRACE   0x40
 Log level for trace messages. More...
 
#define UCX_LOGGER_LEVEL   0x01
 Output flag for the log level. More...
 
#define UCX_LOGGER_TIMESTAMP   0x02
 Output flag for the timestmap. More...
 
#define UCX_LOGGER_SOURCE   0x04
 Output flag for the source. More...
 
#define ucx_logger_register_level(logger, level, name)
 Registers a custom log level. More...
 
#define ucx_logger_log(logger, level, ...)   ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
 Logs a message at the specified level. More...
 
#define ucx_logger_error(logger, ...)   ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
 Shortcut for logging an error message. More...
 
#define ucx_logger_info(logger, ...)   ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
 Shortcut for logging an information message. More...
 
#define ucx_logger_warn(logger, ...)   ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
 Shortcut for logging a warning message. More...
 
#define ucx_logger_debug(logger, ...)   ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
 Shortcut for logging a debug message. More...
 
#define ucx_logger_trace(logger, ...)   ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
 Shortcut for logging a trace message. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Functions

UcxLoggerucx_logger_new (void *stream, unsigned int level, unsigned int mask)
 Creates a new logger. More...
 
void ucx_logger_free (UcxLogger *logger)
 Destroys the logger. More...
 
void ucx_logger_logf (UcxLogger *logger, unsigned int level, const char *file, const unsigned int line, const char *format,...)
 Internal log function - use macros instead. More...
 
universe@390:

Detailed Description

universe@390:

Logging API.

universe@390:
Author
Mike Becker, Olaf Wintermann
universe@390:

Macro Definition Documentation

universe@390: universe@390:

◆ UCX_LOGGER_DEBUG

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_DEBUG   0x30
universe@390:
universe@390: universe@390:

Log level for debug messages.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_debug

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_debug( logger,
 ... 
)   ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Shortcut for logging a debug message.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_ERROR

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_ERROR   0x00
universe@390:
universe@390: universe@390:

Log level for error messages.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_error

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_error( logger,
 ... 
)   ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Shortcut for logging an error message.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_INFO

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_INFO   0x20
universe@390:
universe@390: universe@390:

Log level for information messages.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_info

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_info( logger,
 ... 
)   ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Shortcut for logging an information message.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_LEVEL

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_LEVEL   0x01
universe@390:
universe@390: universe@390:

Output flag for the log level.

universe@390:

If this flag is set, the log message will contain the log level.

See also
UcxLogger.mask
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_log

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_log( logger,
 level,
 ... 
)   ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Logs a message at the specified level.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
levelthe level to log the message on
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_register_level

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_register_level( logger,
 level,
 name 
)
universe@390:
universe@390: Value:
{\
unsigned int l; \
l = level; \
ucx_map_int_put(logger->levels, l, (void*) "[" name "]"); \
} while (0);
universe@390:

Registers a custom log level.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
loggerthe logger
levelthe log level as unsigned integer
namea string literal describing the level
universe@390:
universe@390:
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_SOURCE

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_SOURCE   0x04
universe@390:
universe@390: universe@390:

Output flag for the source.

universe@390:

If this flag is set, the log message will contain the source file and line number.

See also
UcxLogger.mask
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_TIMESTAMP

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_TIMESTAMP   0x02
universe@390:
universe@390: universe@390:

Output flag for the timestmap.

universe@390:

If this flag is set, the log message will contain the timestmap.

See also
UcxLogger.mask
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_TRACE

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_TRACE   0x40
universe@390:
universe@390: universe@390:

Log level for trace messages.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_trace

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_trace( logger,
 ... 
)   ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Shortcut for logging a trace message.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ UCX_LOGGER_WARN

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_LOGGER_WARN   0x10
universe@390:
universe@390: universe@390:

Log level for warning messages.

universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_warn

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define ucx_logger_warn( logger,
 ... 
)   ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
universe@390:
universe@390: universe@390:

Shortcut for logging a warning message.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
...format string and arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_logf()
universe@390: universe@390:
universe@390:
universe@390:

Function Documentation

universe@390: universe@390:

◆ ucx_logger_free()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_logger_free (UcxLoggerlogger)
universe@390:
universe@390: universe@390:

Destroys the logger.

universe@390:

The map containing the valid log levels is also automatically destroyed.

universe@390:
Parameters
universe@390: universe@390: universe@390:
loggerthe logger to destroy
universe@390:
universe@390:
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_logf()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_logger_logf (UcxLoggerlogger,
unsigned int level,
const char * file,
const unsigned int line,
const char * format,
 ... 
)
universe@390:
universe@390: universe@390:

Internal log function - use macros instead.

universe@390:

This function uses the format and variadic arguments for a printf()-style output of the log message.

universe@390:

Dependent on the UcxLogger.mask some information is prepended. The complete format is:

universe@390:

[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message

universe@390:

Attention: the message (including automatically generated information) is limited to 4096 characters. The level description is limited to 256 characters and the timestamp string is limited to 128 characters.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
loggerthe logger to use
levelthe level to log on
fileinformation about the source file
lineinformation about the source line number
formatformat string
...arguments
universe@390:
universe@390:
universe@390:
See also
ucx_logger_log()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_logger_new()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxLogger* ucx_logger_new (void * stream,
unsigned int level,
unsigned int mask 
)
universe@390:
universe@390: universe@390:

Creates a new logger.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
streamthe stream, which the logger shall write to
levelthe level on which the logger shall operate
maskconfiguration mask (cf. UcxLogger.mask)
universe@390:
universe@390:
universe@390:
Returns
a new logger object
universe@390: universe@390:
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: