libprom  @VERSION@
C based libraries to expose metrics in Promtheus exposition format
prom_log.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Jens Elkner <jel+libprom@cs.uni-magdeburg.de>.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef PROM_LOG_H
23 #define PROM_LOG_H
24 
25 #ifdef PROM_LOG_ENABLE
26 
27 #include <stdio.h>
28 
32 typedef enum {
33  PLL_NONE = 0,
41 
57 void prom_log(PROM_LOG_LEVEL level, const char* format, ...);
58 
66 
74 PROM_LOG_LEVEL prom_log_level_parse(const char *level);
75 
87 FILE *prom_log_use(FILE *stream);
88 
89 #define PROM_LOG_PRIV(level, fmt, ...) \
90  prom_log(level, "%s:%d::%s(): " fmt , \
91  __FILE__, __LINE__, __func__, __VA_ARGS__);
92 
97 #define PROM_DEBUG(fmt, ...) PROM_LOG_PRIV(PLL_DBG, fmt, __VA_ARGS__);
98 
102 #define PROM_INFO(fmt, ...) PROM_LOG_PRIV(PLL_INFO, fmt, __VA_ARGS__);
103 
107 #define PROM_WARN(fmt, ...) PROM_LOG_PRIV(PLL_WARN, fmt, __VA_ARGS__);
108 
112 #define PROM_ERROR(fmt, ...) PROM_LOG_PRIV(PLL_ERR, fmt, __VA_ARGS__);
113 
117 #define PROM_FATAL(fmt, ...) PROM_LOG_PRIV(PLL_FATAL, fmt, __VA_ARGS__);
118 
122 #define PROM_LOG(msg) PROM_INFO("%s", msg);
123 
124 #else
125 
126 #define PROM_DEBUG(fmt, ...)
127 #define PROM_INFO(fmt, ...)
128 #define PROM_WARN(fmt, ...)
129 #define PROM_ERROR(fmt, ...)
130 #define PROM_FATAL(fmt, ...)
131 #define PROM_LOG(msg)
132 
133 #define prom_log(x, fmt, ...)
134 #define prom_log_level(x) 0
135 #define prom_log_level_parse(x) 0
136 #define prom_log_use(x) NULL
137 
138 #endif // PROM_LOG_ENABLE
139 
140 #endif // PROM_LOG_H
PLL_FATAL
@ PLL_FATAL
fatal level
Definition: prom_log.h:38
PLL_INFO
@ PLL_INFO
info level
Definition: prom_log.h:35
PLL_WARN
@ PLL_WARN
warning level
Definition: prom_log.h:36
prom_log
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,...
prom_log_use
FILE * prom_log_use(FILE *stream)
Use the given stream for logging.
PLL_NONE
@ PLL_NONE
placeholder for 0 - implies nothing.
Definition: prom_log.h:33
PLL_COUNT
@ PLL_COUNT
number of log levels
Definition: prom_log.h:39
PLL_DBG
@ PLL_DBG
debug level
Definition: prom_log.h:34
PROM_LOG_LEVEL
PROM_LOG_LEVEL
Available log levels.
Definition: prom_log.h:32
PLL_ERR
@ PLL_ERR
error level
Definition: prom_log.h:37
prom_log_level_parse
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 i...
prom_log_level
PROM_LOG_LEVEL prom_log_level(PROM_LOG_LEVEL level)
Set the current log level.