libprom @VERSION@
C based libraries to expose metrics in Promtheus exposition format
Loading...
Searching...
No Matches
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
41
57void prom_log(PROM_LOG_LEVEL level, const char* format, ...);
58
66
75
87FILE *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__);
102#define PROM_INFO(fmt, ...) PROM_LOG_PRIV(PLL_INFO, fmt, __VA_ARGS__);
107#define PROM_WARN(fmt, ...) PROM_LOG_PRIV(PLL_WARN, fmt, __VA_ARGS__);
112#define PROM_ERROR(fmt, ...) PROM_LOG_PRIV(PLL_ERR, fmt, __VA_ARGS__);
117#define PROM_FATAL(fmt, ...) PROM_LOG_PRIV(PLL_FATAL, fmt, __VA_ARGS__);
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
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...
FILE * prom_log_use(FILE *stream)
Use the given stream for logging.
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_LEVEL
Available log levels.
Definition prom_log.h:32
@ PLL_ERR
error level
Definition prom_log.h:37
@ PLL_DBG
debug level
Definition prom_log.h:34
@ PLL_FATAL
fatal level
Definition prom_log.h:38
@ PLL_INFO
info level
Definition prom_log.h:35
@ PLL_NONE
placeholder for 0 - implies nothing.
Definition prom_log.h:33
@ PLL_COUNT
number of log levels
Definition prom_log.h:39
@ PLL_WARN
warning level
Definition prom_log.h:36
PROM_LOG_LEVEL prom_log_level(PROM_LOG_LEVEL level)
Set the current log level.