libprom  @VERSION@
C based libraries to expose metrics in Promtheus exposition format
Defines | Enumerations | Functions
prom/include/prom_log.h File Reference

logging More...

#include <stdio.h>
Include dependency graph for prom_log.h:

Go to the source code of this file.

Defines

#define PROM_LOG_PRIV(level, fmt,...)
#define PROM_DEBUG(fmt,...)   PROM_LOG_PRIV(PLL_DBG, fmt, __VA_ARGS__);
 Log a debug message prefixed with the location of this macro within the source code (file, line, function).
#define PROM_INFO(fmt,...)   PROM_LOG_PRIV(PLL_INFO, fmt, __VA_ARGS__);
 Log an info message prefixed with the location of this macro within the source code (file, line, function).
#define PROM_WARN(fmt,...)   PROM_LOG_PRIV(PLL_WARN, fmt, __VA_ARGS__);
 Log a warn message prefixed with the location of this macro within the source code (file, line, function).
#define PROM_ERROR(fmt,...)   PROM_LOG_PRIV(PLL_ERR, fmt, __VA_ARGS__);
 Log an error message prefixed with the location of this macro within the source code (file, line, function).
#define PROM_FATAL(fmt,...)   PROM_LOG_PRIV(PLL_FATAL, fmt, __VA_ARGS__);
 Log a fatal message prefixed with the location of this macro within the source code (file, line, function).
#define PROM_LOG(msg)   PROM_INFO("%s", msg);
 Log a info message prefixed with the location of this macro within the source code (file, line, function), which has no optional arg.

Enumerations

enum  PROM_LOG_LEVEL {
  PLL_NONE = 0, PLL_DBG, PLL_INFO, PLL_WARN,
  PLL_ERR, PLL_FATAL, PLL_COUNT
}
 Available log levels. More...

Functions

void prom_log (PROM_LOG_LEVEL level, const char *format,...)
 If the given PROM_LOG_LEVEL is >= the log level set, generate and log a related message, otherwise do nothing.
PROM_LOG_LEVEL prom_log_level (PROM_LOG_LEVEL level)
 Set the current log level.
PROM_LOG_LEVEL prom_log_level_parse (const char *level)
 Parse the given log level name (for convenience, a single digit gets recognized as well) and return its corresponding log level value.
FILE * prom_log_use (FILE *stream)
 Use the given stream for logging.

Detailed Description

logging


Define Documentation

#define PROM_LOG_PRIV (   level,
  fmt,
  ... 
)
Value:
prom_log(level, "%s:%d::%s(): " fmt , \
        __FILE__, __LINE__, __func__, __VA_ARGS__);

Enumeration Type Documentation

Available log levels.

Enumerator:
PLL_NONE 

placeholder for 0 - implies nothing.

Do not use!

PLL_DBG 

debug level

PLL_INFO 

info level

PLL_WARN 

warning level

PLL_ERR 

error level

PLL_FATAL 

fatal level

PLL_COUNT 

number of log levels


Function Documentation

void prom_log ( PROM_LOG_LEVEL  level,
const char *  format,
  ... 
)

If the given PROM_LOG_LEVEL is >= the log level set, generate and log a related message, otherwise do nothing.

Right now format and the optional arguments get passed to printf() as is and the related string pushed to stderr with a trailing linefeed. The log level to compare to, if not already set, gets determined the first time this function gets called: It evaluates the environment variable **PROM_LOG_LEVEL**. If it is unset or has an unknown value, INFO will be used. Otherwise the corresponding level for DEBUG, INFO, WARN, ERROR, or FATAL.

Parameters:
PROM_LOG_LEVELLog level to use to decide, whether to log.
formatSame as for printf(3).
...Optional format args.

Set the current log level.

Parameters:
levelThe loglevel to set. Use PLL_NONE to get the loglevel currently set returned and the current loglevel stays untouched.
Returns:
The previously loglevel used (might be PLL_NONE, if not yet set).
PROM_LOG_LEVEL prom_log_level_parse ( const char *  level)

Parse the given log level name (for convenience, a single digit gets recognized as well) and return its corresponding log level value.

Parameters:
levelName of the log level or its corresponding value to parse.
Returns:
PLL_NONE if the given level name could not be parsed successfully, the corresponding log level value otherwise.
FILE* prom_log_use ( FILE *  stream)

Use the given stream for logging.

This function duplicates the stream's underlying file descriptor, opens it in APPEND mode and writes from now on all messages to it. It gets automatically flushed and synced linewise. The callee should close the given stream to avoid any garbage.

Parameters:
streamStream to use for logging. NULL or invalid streams are ignored.
Returns:
NULL on failure, the previously used logging stream (which is initially stderr ) otherwise. The callee should close it, if not needed anymore.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines