oRTP  0.24.0
include/ortp/logging.h
Go to the documentation of this file.
00001 /*
00002   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
00003   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00026 #ifndef ORTP_LOGGING_H
00027 #define ORTP_LOGGING_H
00028 
00029 #include <ortp/port.h>
00030 
00031 #ifdef __cplusplus
00032 extern "C"
00033 {
00034 #endif
00035 
00036 typedef enum {
00037         ORTP_DEBUG=1,
00038         ORTP_MESSAGE=1<<1,
00039         ORTP_WARNING=1<<2,
00040         ORTP_ERROR=1<<3,
00041         ORTP_FATAL=1<<4,
00042         ORTP_TRACE=1<<5,
00043         ORTP_LOGLEV_END=1<<6
00044 } OrtpLogLevel;
00045 
00046 
00047 typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
00048 
00049 ORTP_PUBLIC void ortp_set_log_file(FILE *file);
00050 ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func);
00051 ORTP_PUBLIC OrtpLogFunc ortp_get_log_handler();
00052 
00053 ORTP_VAR_PUBLIC OrtpLogFunc ortp_logv_out;
00054 
00055 #define ortp_log_level_enabled(level)   (ortp_get_log_level_mask() & (level))
00056 
00057 ORTP_PUBLIC void ortp_logv(int level, const char *fmt, va_list args);
00058 
00063 ORTP_PUBLIC void ortp_logv_flush(void);
00064 
00065 ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask);
00066 ORTP_PUBLIC int ortp_get_log_level_mask(void);
00067 
00073 ORTP_PUBLIC void ortp_set_log_thread_id(unsigned long thread_id);
00074 
00075 #ifdef __GNUC__
00076 #define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
00077 #else
00078 #define CHECK_FORMAT_ARGS(m,n)
00079 #endif
00080 #ifdef __clang__
00081 /*in case of compile with -g static inline can produce this type of warning*/
00082 #pragma GCC diagnostic ignored "-Wunused-function"
00083 #endif
00084 #ifdef ORTP_DEBUG_MODE
00085 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
00086 {
00087   va_list args;
00088   va_start (args, fmt);
00089   ortp_logv(ORTP_DEBUG, fmt, args);
00090   va_end (args);
00091 }
00092 #else
00093 
00094 #define ortp_debug(...)
00095 
00096 #endif
00097 
00098 #ifdef ORTP_NOMESSAGE_MODE
00099 
00100 #define ortp_log(...)
00101 #define ortp_message(...)
00102 #define ortp_warning(...)
00103 
00104 #else
00105 
00106 static ORTP_INLINE void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
00107         va_list args;
00108         va_start (args, fmt);
00109         ortp_logv(lev, fmt, args);
00110         va_end (args);
00111 }
00112 
00113 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
00114 {
00115         va_list args;
00116         va_start (args, fmt);
00117         ortp_logv(ORTP_MESSAGE, fmt, args);
00118         va_end (args);
00119 }
00120 
00121 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
00122 {
00123         va_list args;
00124         va_start (args, fmt);
00125         ortp_logv(ORTP_WARNING, fmt, args);
00126         va_end (args);
00127 }
00128 
00129 #endif
00130 
00131 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
00132 {
00133         va_list args;
00134         va_start (args, fmt);
00135         ortp_logv(ORTP_ERROR, fmt, args);
00136         va_end (args);
00137 }
00138 
00139 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
00140 {
00141         va_list args;
00142         va_start (args, fmt);
00143         ortp_logv(ORTP_FATAL, fmt, args);
00144         va_end (args);
00145 }
00146 
00147 
00148 #ifdef __QNX__
00149 void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args);
00150 #endif
00151 
00152 
00153 #ifdef __cplusplus
00154 }
00155 #endif
00156 
00157 #endif