BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

log.h
Go to the documentation of this file.
1 /* $Id: log.h 3752 2011-09-18 14:38:46Z bennylp $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJ_LOG_H__
21 #define __PJ_LOG_H__
22 
28 #include <pj/types.h>
29 #include <stdarg.h>
30 
32 
71 {
80  PJ_LOG_HAS_CR = 256,
87 };
88 
107 #define PJ_LOG(level,arg) do { \
108  if (level <= pj_log_get_level()) \
109  pj_log_wrapper_##level(arg); \
110  } while (0)
111 
120 typedef void pj_log_func(int level, const char *data, int len);
121 
132 PJ_DECL(void) pj_log_write(int level, const char *buffer, int len);
133 
134 
135 #if PJ_LOG_MAX_LEVEL >= 1
136 
145 PJ_DECL(void) pj_log(const char *sender, int level,
146  const char *format, va_list marker);
147 
157 PJ_DECL(void) pj_log_set_log_func( pj_log_func *func );
158 
164 PJ_DECL(pj_log_func*) pj_log_get_log_func(void);
165 
176 PJ_DECL(void) pj_log_set_level(int level);
177 
183 #if 1
184 PJ_DECL(int) pj_log_get_level(void);
185 #else
186 PJ_DECL_DATA(int) pj_log_max_level;
187 #define pj_log_get_level() pj_log_max_level
188 #endif
189 
199 PJ_DECL(void) pj_log_set_decor(unsigned decor);
200 
206 PJ_DECL(unsigned) pj_log_get_decor(void);
207 
216 PJ_DECL(void) pj_log_add_indent(int indent);
217 
221 PJ_DECL(void) pj_log_push_indent(void);
222 
226 PJ_DECL(void) pj_log_pop_indent(void);
227 
234 PJ_DECL(void) pj_log_set_color(int level, pj_color_t color);
235 
242 PJ_DECL(pj_color_t) pj_log_get_color(int level);
243 
248 
249 #else /* #if PJ_LOG_MAX_LEVEL >= 1 */
250 
260 # define pj_log_set_log_func(func)
261 
272 # define pj_log_set_level(level)
273 
283 # define pj_log_set_decor(decor)
284 
291 # define pj_log_set_color(level, color)
292 
298 # define pj_log_get_level() 0
299 
305 # define pj_log_get_decor() 0
306 
313 # define pj_log_get_color(level) 0
314 
315 
319 # define pj_log_init() PJ_SUCCESS
320 
321 #endif /* #if PJ_LOG_MAX_LEVEL >= 1 */
322 
327 /* **************************************************************************/
328 /*
329  * Log functions implementation prototypes.
330  * These functions are called by PJ_LOG macros according to verbosity
331  * level specified when calling the macro. Applications should not normally
332  * need to call these functions directly.
333  */
334 
341 #if PJ_LOG_MAX_LEVEL >= 1
342  #define pj_log_wrapper_1(arg) pj_log_1 arg
343 
344  PJ_DECL(void) pj_log_1(const char *src, const char *format, ...);
345 #else
346  #define pj_log_wrapper_1(arg)
347 #endif
348 
355 #if PJ_LOG_MAX_LEVEL >= 2
356  #define pj_log_wrapper_2(arg) pj_log_2 arg
357 
358  PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
359 #else
360  #define pj_log_wrapper_2(arg)
361 #endif
362 
369 #if PJ_LOG_MAX_LEVEL >= 3
370  #define pj_log_wrapper_3(arg) pj_log_3 arg
371 
372  PJ_DECL(void) pj_log_3(const char *src, const char *format, ...);
373 #else
374  #define pj_log_wrapper_3(arg)
375 #endif
376 
383 #if PJ_LOG_MAX_LEVEL >= 4
384  #define pj_log_wrapper_4(arg) pj_log_4 arg
385 
386  PJ_DECL(void) pj_log_4(const char *src, const char *format, ...);
387 #else
388  #define pj_log_wrapper_4(arg)
389 #endif
390 
397 #if PJ_LOG_MAX_LEVEL >= 5
398  #define pj_log_wrapper_5(arg) pj_log_5 arg
399 
400  PJ_DECL(void) pj_log_5(const char *src, const char *format, ...);
401 #else
402  #define pj_log_wrapper_5(arg)
403 #endif
404 
411 #if PJ_LOG_MAX_LEVEL >= 6
412  #define pj_log_wrapper_6(arg) pj_log_6 arg
413 
414  PJ_DECL(void) pj_log_6(const char *src, const char *format, ...);
415 #else
416  #define pj_log_wrapper_6(arg)
417 #endif
418 
419 
421 
422 #endif /* __PJ_LOG_H__ */
423 

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.