BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

log.h
Go to the documentation of this file.
1 /* $Id: log.h 5317 2016-05-25 06:33:26Z ming $ */
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  } \
111  } while (0)
112 
121 typedef void pj_log_func(int level, const char *data, int len);
122 
133 PJ_DECL(void) pj_log_write(int level, const char *buffer, int len);
134 
135 
136 #if PJ_LOG_MAX_LEVEL >= 1
137 
146 PJ_DECL(void) pj_log(const char *sender, int level,
147  const char *format, va_list marker);
148 
158 PJ_DECL(void) pj_log_set_log_func( pj_log_func *func );
159 
165 PJ_DECL(pj_log_func*) pj_log_get_log_func(void);
166 
177 PJ_DECL(void) pj_log_set_level(int level);
178 
184 #if 1
185 PJ_DECL(int) pj_log_get_level(void);
186 #else
187 PJ_DECL_DATA(int) pj_log_max_level;
188 #define pj_log_get_level() pj_log_max_level
189 #endif
190 
200 PJ_DECL(void) pj_log_set_decor(unsigned decor);
201 
207 PJ_DECL(unsigned) pj_log_get_decor(void);
208 
217 PJ_DECL(void) pj_log_add_indent(int indent);
218 
222 PJ_DECL(void) pj_log_push_indent(void);
223 
227 PJ_DECL(void) pj_log_pop_indent(void);
228 
235 PJ_DECL(void) pj_log_set_color(int level, pj_color_t color);
236 
243 PJ_DECL(pj_color_t) pj_log_get_color(int level);
244 
249 
250 #else /* #if PJ_LOG_MAX_LEVEL >= 1 */
251 
261 # define pj_log_set_log_func(func)
262 
271 # define pj_log(sender, level, format, marker)
272 
283 # define pj_log_set_level(level)
284 
294 # define pj_log_set_decor(decor)
295 
304 # define pj_log_add_indent(indent)
305 
309 # define pj_log_push_indent()
310 
314 # define pj_log_pop_indent()
315 
322 # define pj_log_set_color(level, color)
323 
329 # define pj_log_get_level() 0
330 
336 # define pj_log_get_decor() 0
337 
344 # define pj_log_get_color(level) 0
345 
346 
350 # define pj_log_init() PJ_SUCCESS
351 
352 #endif /* #if PJ_LOG_MAX_LEVEL >= 1 */
353 
358 /* **************************************************************************/
359 /*
360  * Log functions implementation prototypes.
361  * These functions are called by PJ_LOG macros according to verbosity
362  * level specified when calling the macro. Applications should not normally
363  * need to call these functions directly.
364  */
365 
372 #if PJ_LOG_MAX_LEVEL >= 1
373  #define pj_log_wrapper_1(arg) pj_log_1 arg
374 
375  PJ_DECL(void) pj_log_1(const char *src, const char *format, ...);
376 #else
377  #define pj_log_wrapper_1(arg)
378 #endif
379 
386 #if PJ_LOG_MAX_LEVEL >= 2
387  #define pj_log_wrapper_2(arg) pj_log_2 arg
388 
389  PJ_DECL(void) pj_log_2(const char *src, const char *format, ...);
390 #else
391  #define pj_log_wrapper_2(arg)
392 #endif
393 
400 #if PJ_LOG_MAX_LEVEL >= 3
401  #define pj_log_wrapper_3(arg) pj_log_3 arg
402 
403  PJ_DECL(void) pj_log_3(const char *src, const char *format, ...);
404 #else
405  #define pj_log_wrapper_3(arg)
406 #endif
407 
414 #if PJ_LOG_MAX_LEVEL >= 4
415  #define pj_log_wrapper_4(arg) pj_log_4 arg
416 
417  PJ_DECL(void) pj_log_4(const char *src, const char *format, ...);
418 #else
419  #define pj_log_wrapper_4(arg)
420 #endif
421 
428 #if PJ_LOG_MAX_LEVEL >= 5
429  #define pj_log_wrapper_5(arg) pj_log_5 arg
430 
431  PJ_DECL(void) pj_log_5(const char *src, const char *format, ...);
432 #else
433  #define pj_log_wrapper_5(arg)
434 #endif
435 
442 #if PJ_LOG_MAX_LEVEL >= 6
443  #define pj_log_wrapper_6(arg) pj_log_6 arg
444 
445  PJ_DECL(void) pj_log_6(const char *src, const char *format, ...);
446 #else
447  #define pj_log_wrapper_6(arg)
448 #endif
449 
450 
452 
453 #endif /* __PJ_LOG_H__ */
454 
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:1096
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:1095
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:121
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.