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 ORTP_PUBLIC void ortp_logv(int level, const char *fmt, va_list args);
57 
62 ORTP_PUBLIC void ortp_logv_flush(void);
63 
64 ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask);
65 ORTP_PUBLIC int ortp_get_log_level_mask(void);
66 
72 ORTP_PUBLIC void ortp_set_log_thread_id(unsigned long thread_id);
73 
74 #ifdef __GNUC__
75 #define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
76 #else
77 #define CHECK_FORMAT_ARGS(m,n)
78 #endif
79 #ifdef __clang__
80 /*in case of compile with -g static inline can produce this type of warning*/
81 #pragma GCC diagnostic ignored "-Wunused-function"
82 #endif
83 #ifdef ORTP_DEBUG_MODE
84 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
85 {
86  va_list args;
87  va_start (args, fmt);
88  ortp_logv(ORTP_DEBUG, fmt, args);
89  va_end (args);
90 }
91 #else
92 
93 #define ortp_debug(...)
94 
95 #endif
96 
97 #ifdef ORTP_NOMESSAGE_MODE
98 
99 #define ortp_log(...)
100 #define ortp_message(...)
101 #define ortp_warning(...)
102 
103 #else
104 
105 static ORTP_INLINE void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
106  va_list args;
107  va_start (args, fmt);
108  ortp_logv(lev, fmt, args);
109  va_end (args);
110 }
111 
112 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
113 {
114  va_list args;
115  va_start (args, fmt);
116  ortp_logv(ORTP_MESSAGE, fmt, args);
117  va_end (args);
118 }
119 
120 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
121 {
122  va_list args;
123  va_start (args, fmt);
124  ortp_logv(ORTP_WARNING, fmt, args);
125  va_end (args);
126 }
127 
128 #endif
129 
130 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
131 {
132  va_list args;
133  va_start (args, fmt);
134  ortp_logv(ORTP_ERROR, fmt, args);
135  va_end (args);
136 }
137 
138 static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
139 {
140  va_list args;
141  va_start (args, fmt);
142  ortp_logv(ORTP_FATAL, fmt, args);
143  va_end (args);
144 }
145 
146 
147 #ifdef __QNX__
148 void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args);
149 #endif
150 
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif
ORTP_PUBLIC void ortp_logv_flush(void)
Definition: logging.c:195
ORTP_PUBLIC void ortp_set_log_file(FILE *file)
Definition: logging.c:37
ORTP_PUBLIC void ortp_set_log_thread_id(unsigned long thread_id)
Definition: logging.c:69
ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func)
Definition: logging.c:50
ORTP_PUBLIC void ortp_set_log_level_mask(int levelmask)
Definition: logging.c:61