oRTP  0.23.0
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 #define ortp_log_level_enabled(level) (ortp_get_log_level_mask() & (level))
55 
56 #if !defined(WIN32) && !defined(_WIN32_WCE)
57 #define ortp_logv(level,fmt,args) \
58 {\
59  if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
60  ortp_logv_out(level,fmt,args);\
61  if ((level)==ORTP_FATAL) abort();\
62 }while(0)
63 #else
64 ORTP_PUBLIC void ortp_logv(int level, const char *fmt, va_list args);
65 #endif
66 
67 ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask);
68 ORTP_PUBLIC int ortp_get_log_level_mask(void);
69 
70 #ifdef __GNUC__
71 #define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
72 #else
73 #define CHECK_FORMAT_ARGS(m,n)
74 #endif
75 
76 
77 #ifdef ORTP_DEBUG_MODE
78 static inline void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
79 {
80  va_list args;
81  va_start (args, fmt);
82  ortp_logv(ORTP_DEBUG, fmt, args);
83  va_end (args);
84 }
85 #else
86 
87 #define ortp_debug(...)
88 
89 #endif
90 
91 #ifdef ORTP_NOMESSAGE_MODE
92 
93 #define ortp_log(...)
94 #define ortp_message(...)
95 #define ortp_warning(...)
96 
97 #else
98 
99 static inline void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
100  va_list args;
101  va_start (args, fmt);
102  ortp_logv(lev, fmt, args);
103  va_end (args);
104 }
105 
106 static inline void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
107 {
108  va_list args;
109  va_start (args, fmt);
110  ortp_logv(ORTP_MESSAGE, fmt, args);
111  va_end (args);
112 }
113 
114 static inline void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
115 {
116  va_list args;
117  va_start (args, fmt);
118  ortp_logv(ORTP_WARNING, fmt, args);
119  va_end (args);
120 }
121 
122 #endif
123 
124 static inline void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
125 {
126  va_list args;
127  va_start (args, fmt);
128  ortp_logv(ORTP_ERROR, fmt, args);
129  va_end (args);
130 }
131 
132 static inline void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
133 {
134  va_list args;
135  va_start (args, fmt);
136  ortp_logv(ORTP_FATAL, fmt, args);
137  va_end (args);
138 }
139 
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif
ORTP_PUBLIC void ortp_set_log_file(FILE *file)
Definition: logging.c:30
ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func)
Definition: logging.c:43
ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask)
Definition: logging.c:54