oRTP  0.22.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 
00052 ORTP_VAR_PUBLIC OrtpLogFunc ortp_logv_out;
00053 
00054 #define ortp_log_level_enabled(level)   (ortp_get_log_level_mask() & (level))
00055 
00056 #if !defined(WIN32) && !defined(_WIN32_WCE)
00057 #define ortp_logv(level,fmt,args) \
00058 {\
00059         if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
00060                 ortp_logv_out(level,fmt,args);\
00061         if ((level)==ORTP_FATAL) abort();\
00062 }while(0)
00063 #else
00064 ORTP_PUBLIC void ortp_logv(int level, const char *fmt, va_list args);
00065 #endif
00066 
00067 ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask);
00068 ORTP_PUBLIC int ortp_get_log_level_mask(void);
00069 
00070 #ifdef __GNUC__
00071 #define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
00072 #else
00073 #define CHECK_FORMAT_ARGS(m,n)
00074 #endif
00075 
00076 
00077 #ifdef ORTP_DEBUG_MODE
00078 static inline void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
00079 {
00080   va_list args;
00081   va_start (args, fmt);
00082   ortp_logv(ORTP_DEBUG, fmt, args);
00083   va_end (args);
00084 }
00085 #else
00086 
00087 #define ortp_debug(...)
00088 
00089 #endif
00090 
00091 #ifdef ORTP_NOMESSAGE_MODE
00092 
00093 #define ortp_log(...)
00094 #define ortp_message(...)
00095 #define ortp_warning(...)
00096 
00097 #else
00098 
00099 static inline void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
00100         va_list args;
00101         va_start (args, fmt);
00102         ortp_logv(lev, fmt, args);
00103         va_end (args);
00104 }
00105 
00106 static inline void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
00107 {
00108         va_list args;
00109         va_start (args, fmt);
00110         ortp_logv(ORTP_MESSAGE, fmt, args);
00111         va_end (args);
00112 }
00113 
00114 static inline void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
00115 {
00116         va_list args;
00117         va_start (args, fmt);
00118         ortp_logv(ORTP_WARNING, fmt, args);
00119         va_end (args);
00120 }
00121 
00122 #endif
00123 
00124 static inline void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
00125 {
00126         va_list args;
00127         va_start (args, fmt);
00128         ortp_logv(ORTP_ERROR, fmt, args);
00129         va_end (args);
00130 }
00131 
00132 static inline void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
00133 {
00134         va_list args;
00135         va_start (args, fmt);
00136         ortp_logv(ORTP_FATAL, fmt, args);
00137         va_end (args);
00138 }
00139 
00140 
00141 #ifdef __cplusplus
00142 }
00143 #endif
00144 
00145 #endif