libprom  @VERSION@
C based libraries to expose metrics in Promtheus exposition format
prom/include/prom_log.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2021 Jens Elkner <jel+libprom@cs.uni-magdeburg.de>.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef PROM_LOG_H
00023 #define PROM_LOG_H
00024 
00025 #ifdef PROM_LOG_ENABLE
00026 
00027 #include <stdio.h>
00028 
00032 typedef enum {
00033     PLL_NONE = 0,   
00034     PLL_DBG,        
00035     PLL_INFO,       
00036     PLL_WARN,       
00037     PLL_ERR,        
00038     PLL_FATAL,      
00039     PLL_COUNT       
00040 } PROM_LOG_LEVEL;
00041 
00057 void prom_log(PROM_LOG_LEVEL level, const char* format, ...);
00058 
00065 PROM_LOG_LEVEL prom_log_level(PROM_LOG_LEVEL level);
00066 
00074 PROM_LOG_LEVEL prom_log_level_parse(const char *level);
00075 
00087 FILE *prom_log_use(FILE *stream);
00088 
00089 #define PROM_LOG_PRIV(level, fmt, ...)  \
00090     prom_log(level, "%s:%d::%s(): " fmt , \
00091         __FILE__, __LINE__, __func__, __VA_ARGS__);
00092 
00097 #define PROM_DEBUG(fmt, ...)    PROM_LOG_PRIV(PLL_DBG, fmt, __VA_ARGS__);
00098 
00102 #define PROM_INFO(fmt, ...)     PROM_LOG_PRIV(PLL_INFO, fmt, __VA_ARGS__);
00103 
00107 #define PROM_WARN(fmt, ...)     PROM_LOG_PRIV(PLL_WARN, fmt, __VA_ARGS__);
00108 
00112 #define PROM_ERROR(fmt, ...)    PROM_LOG_PRIV(PLL_ERR, fmt, __VA_ARGS__);
00113 
00117 #define PROM_FATAL(fmt, ...)    PROM_LOG_PRIV(PLL_FATAL, fmt, __VA_ARGS__);
00118 
00122 #define PROM_LOG(msg)           PROM_INFO("%s", msg);
00123 
00124 #else
00125 
00126 #define PROM_DEBUG(fmt, ...)
00127 #define PROM_INFO(fmt, ...)
00128 #define PROM_WARN(fmt, ...)
00129 #define PROM_ERROR(fmt, ...)
00130 #define PROM_FATAL(fmt, ...)
00131 #define PROM_LOG(msg)
00132 
00133 #define prom_log(x, fmt, ...)
00134 #define prom_log_level(x) 0
00135 #define prom_log_level_parse(x) 0
00136 #define prom_log_use(x) NULL
00137 
00138 #endif  // PROM_LOG_ENABLE
00139 
00140 #endif  // PROM_LOG_H
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines