ucx
UAP Common Extensions
Data Structures | Macros | Functions
logging.h File Reference

Logging API. More...

#include "ucx.h"
#include "map.h"
#include "string.h"
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  UcxLogger
 The UCX Logger object. More...
 

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

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

Detailed Description

Logging API.

Author
Mike Becker, Olaf Wintermann

Macro Definition Documentation

◆ UCX_LOGGER_DEBUG

#define UCX_LOGGER_DEBUG   0x30

Log level for debug messages.

◆ ucx_logger_debug

#define ucx_logger_debug (   logger,
  ... 
)    ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)

Shortcut for logging a debug message.

Parameters
loggerthe logger to use
...format string and arguments
See also
ucx_logger_logf()

◆ UCX_LOGGER_ERROR

#define UCX_LOGGER_ERROR   0x00

Log level for error messages.

◆ ucx_logger_error

#define ucx_logger_error (   logger,
  ... 
)    ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)

Shortcut for logging an error message.

Parameters
loggerthe logger to use
...format string and arguments
See also
ucx_logger_logf()

◆ UCX_LOGGER_INFO

#define UCX_LOGGER_INFO   0x20

Log level for information messages.

◆ ucx_logger_info

#define ucx_logger_info (   logger,
  ... 
)    ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)

Shortcut for logging an information message.

Parameters
loggerthe logger to use
...format string and arguments
See also
ucx_logger_logf()

◆ UCX_LOGGER_LEVEL

#define UCX_LOGGER_LEVEL   0x01

Output flag for the log level.

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

See also
UcxLogger.mask

◆ ucx_logger_log

#define ucx_logger_log (   logger,
  level,
  ... 
)    ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)

Logs a message at the specified level.

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

◆ ucx_logger_register_level

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

Registers a custom log level.

Parameters
loggerthe logger
levelthe log level as unsigned integer
namea string literal describing the level

◆ UCX_LOGGER_SOURCE

#define UCX_LOGGER_SOURCE   0x04

Output flag for the source.

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

See also
UcxLogger.mask

◆ UCX_LOGGER_TIMESTAMP

#define UCX_LOGGER_TIMESTAMP   0x02

Output flag for the timestmap.

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

See also
UcxLogger.mask

◆ UCX_LOGGER_TRACE

#define UCX_LOGGER_TRACE   0x40

Log level for trace messages.

◆ ucx_logger_trace

#define ucx_logger_trace (   logger,
  ... 
)    ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)

Shortcut for logging a trace message.

Parameters
loggerthe logger to use
...format string and arguments
See also
ucx_logger_logf()

◆ UCX_LOGGER_WARN

#define UCX_LOGGER_WARN   0x10

Log level for warning messages.

◆ ucx_logger_warn

#define ucx_logger_warn (   logger,
  ... 
)    ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)

Shortcut for logging a warning message.

Parameters
loggerthe logger to use
...format string and arguments
See also
ucx_logger_logf()

Function Documentation

◆ ucx_logger_free()

void ucx_logger_free ( UcxLogger logger)

Destroys the logger.

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

Parameters
loggerthe logger to destroy

◆ ucx_logger_logf()

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.

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

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

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

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.

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

◆ ucx_logger_new()

UcxLogger* ucx_logger_new ( void *  stream,
unsigned int  level,
unsigned int  mask 
)

Creates a new logger.

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