libprom
@VERSION@
C based libraries to expose metrics in Promtheus exposition format
|
logging More...
#include <stdio.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. |
logging
#define PROM_LOG_PRIV | ( | level, | |
fmt, | |||
... | |||
) |
prom_log(level, "%s:%d::%s(): " fmt , \ __FILE__, __LINE__, __func__, __VA_ARGS__);
enum PROM_LOG_LEVEL |
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
.
PROM_LOG_LEVEL | Log level to use to decide, whether to log. |
format | Same as for printf(3) . |
... | Optional format args. |
PROM_LOG_LEVEL prom_log_level | ( | PROM_LOG_LEVEL | level | ) |
Set the current log level.
level | The loglevel to set. Use PLL_NONE to get the loglevel currently set returned and the current loglevel stays untouched. |
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.
level | Name of the log level or its corresponding value to parse. |
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.
stream | Stream to use for logging. NULL or invalid streams are ignored. |
NULL
on failure, the previously used logging stream (which is initially stderr
) otherwise. The callee should close it, if not needed anymore.