BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

log.h
Go to the documentation of this file.
1 /* $Id: log.h 4584 2013-08-30 04:03:22Z 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 
270 # define pj_log(sender, level, format, marker)
271 
282 # define pj_log_set_level(level)
283 
293 # define pj_log_set_decor(decor)
294 
303 # define pj_log_add_indent(indent)
304 
308 # define pj_log_push_indent()
309 
313 # define pj_log_pop_indent()
314 
321 # define pj_log_set_color(level, color)
322 
328 # define pj_log_get_level() 0
329 
335 # define pj_log_get_decor() 0
336 
343 # define pj_log_get_color(level) 0
344 
345 
349 # define pj_log_init() PJ_SUCCESS
350 
351 #endif /* #if PJ_LOG_MAX_LEVEL >= 1 */
352 
357 /* **************************************************************************/
358 /*
359  * Log functions implementation prototypes.
360  * These functions are called by PJ_LOG macros according to verbosity
361  * level specified when calling the macro. Applications should not normally
362  * need to call these functions directly.
363  */
364 
371 #if PJ_LOG_MAX_LEVEL >= 1
372  #define pj_log_wrapper_1(arg) pj_log_1 arg
373 
374  PJ_DECL(void) pj_log_1(const char *src, const char *format, ...);
375 #else
376  #define pj_log_wrapper_1(arg)
377 #endif
378 
385 #if PJ_LOG_MAX_LEVEL >= 2
386  #define pj_log_wrapper_2(arg) pj_log_2 arg
387 
388  PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
389 #else
390  #define pj_log_wrapper_2(arg)
391 #endif
392 
399 #if PJ_LOG_MAX_LEVEL >= 3
400  #define pj_log_wrapper_3(arg) pj_log_3 arg
401 
402  PJ_DECL(void) pj_log_3(const char *src, const char *format, ...);
403 #else
404  #define pj_log_wrapper_3(arg)
405 #endif
406 
413 #if PJ_LOG_MAX_LEVEL >= 4
414  #define pj_log_wrapper_4(arg) pj_log_4 arg
415 
416  PJ_DECL(void) pj_log_4(const char *src, const char *format, ...);
417 #else
418  #define pj_log_wrapper_4(arg)
419 #endif
420 
427 #if PJ_LOG_MAX_LEVEL >= 5
428  #define pj_log_wrapper_5(arg) pj_log_5 arg
429 
430  PJ_DECL(void) pj_log_5(const char *src, const char *format, ...);
431 #else
432  #define pj_log_wrapper_5(arg)
433 #endif
434 
441 #if PJ_LOG_MAX_LEVEL >= 6
442  #define pj_log_wrapper_6(arg) pj_log_6 arg
443 
444  PJ_DECL(void) pj_log_6(const char *src, const char *format, ...);
445 #else
446  #define pj_log_wrapper_6(arg)
447 #endif
448 
449 
451 
452 #endif /* __PJ_LOG_H__ */
453 
void pj_log_write(int level, const char *buffer, int len)
pj_color_t pj_log_get_color(int level)
void pj_log_push_indent(void)
void pj_log_set_log_func(pj_log_func *func)
void pj_log_3(const char *src, const char *format,...)
int pj_log_get_level(void)
Definition: log.h:76
void pj_log_1(const char *src, const char *format,...)
Definition: log.h:73
Declaration of basic types and utility.
int pj_status_t
Definition: types.h:68
Definition: log.h:77
Definition: log.h:83
Definition: log.h:80
Definition: log.h:75
#define PJ_END_DECL
Definition: config.h:1067
void pj_log(const char *sender, int level, const char *format, va_list marker)
Definition: log.h:74
Definition: log.h:82
void pj_log_set_color(int level, pj_color_t color)
#define PJ_BEGIN_DECL
Definition: config.h:1066
unsigned int pj_color_t
Definition: types.h:273
pj_status_t pj_log_init(void)
Definition: log.h:85
pj_log_func * pj_log_get_log_func(void)
void pj_log_pop_indent(void)
Definition: log.h:81
Definition: log.h:86
void pj_log_add_indent(int indent)
pj_log_decoration
Definition: log.h:70
void pj_log_set_decor(unsigned decor)
void pj_log_4(const char *src, const char *format,...)
void pj_log_2(const char *src, const char *format,...)
Definition: log.h:79
void pj_log_func(int level, const char *data, int len)
Definition: log.h:120
unsigned pj_log_get_decor(void)
Definition: log.h:78
Definition: log.h:72
void pj_log_set_level(int level)
Definition: log.h:84

 


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