oRTP  0.21.1
logging.h
Go to the documentation of this file.
1 /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
26 #ifndef ORTP_LOGGING_H
27 #define ORTP_LOGGING_H
28 
29 #include <ortp/port.h>
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36 typedef enum {
37  ORTP_DEBUG=1,
38  ORTP_MESSAGE=1<<1,
39  ORTP_WARNING=1<<2,
40  ORTP_ERROR=1<<3,
41  ORTP_FATAL=1<<4,
42  ORTP_TRACE=1<<5,
43  ORTP_LOGLEV_END=1<<6
44 } OrtpLogLevel;
45 
46 
47 typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
48 
49 ORTP_PUBLIC void ortp_set_log_file(FILE *file);
50 ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func);
51 
52 ORTP_VAR_PUBLIC OrtpLogFunc ortp_logv_out;
53 
54 ORTP_PUBLIC extern unsigned int __ortp_log_mask;
55 
56 #define ortp_log_level_enabled(level) (__ortp_log_mask & (level))
57 
58 #if !defined(WIN32) && !defined(_WIN32_WCE)
59 #define ortp_logv(level,fmt,args) \
60 {\
61  if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
62  ortp_logv_out(level,fmt,args);\
63  if ((level)==ORTP_FATAL) abort();\
64 }while(0)
65 #else
66 ORTP_PUBLIC void ortp_logv(int level, const char *fmt, va_list args);
67 #endif
68 
69 ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask);
70 
71 #ifdef __GNUC__
72 #define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
73 #else
74 #define CHECK_FORMAT_ARGS(m,n)
75 #endif
76 
77 
78 #ifdef ORTP_DEBUG_MODE
79 static inline void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
80 {
81  va_list args;
82  va_start (args, fmt);
83  ortp_logv(ORTP_DEBUG, fmt, args);
84  va_end (args);
85 }
86 #else
87 
88 #define ortp_debug(...)
89 
90 #endif
91 
92 #ifdef ORTP_NOMESSAGE_MODE
93 
94 #define ortp_log(...)
95 #define ortp_message(...)
96 #define ortp_warning(...)
97 
98 #else
99 
100 static inline void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
101  va_list args;
102  va_start (args, fmt);
103  ortp_logv(lev, fmt, args);
104  va_end (args);
105 }
106 
107 static inline void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
108 {
109  va_list args;
110  va_start (args, fmt);
111  ortp_logv(ORTP_MESSAGE, fmt, args);
112  va_end (args);
113 }
114 
115 static inline void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
116 {
117  va_list args;
118  va_start (args, fmt);
119  ortp_logv(ORTP_WARNING, fmt, args);
120  va_end (args);
121 }
122 
123 #endif
124 
125 static inline void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
126 {
127  va_list args;
128  va_start (args, fmt);
129  ortp_logv(ORTP_ERROR, fmt, args);
130  va_end (args);
131 }
132 
133 static inline void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
134 {
135  va_list args;
136  va_start (args, fmt);
137  ortp_logv(ORTP_FATAL, fmt, args);
138  va_end (args);
139 }
140 
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif