]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_logbase.h
Provided generic code to maintain and register log domains.
[ulut.git] / ulut / ul_logbase.h
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_logbase.h  - base of standard logging facility
5
6   (C) Copyright 2005 by Pavel Pisa - Originator
7
8   The uLan utilities library can be used, copied and modified under
9   next licenses
10     - GPL - GNU General Public License
11     - LGPL - GNU Lesser General Public License
12     - MPL - Mozilla Public License
13     - and other licenses added by project originators
14   Code can be modified and re-distributed under any combination
15   of the above listed licenses. If contributor does not agree with
16   some of the licenses, he/she can delete appropriate line.
17   Warning, if you delete all lines, you are not allowed to
18   distribute source code and/or binaries utilizing code.
19   
20   See files COPYING and README for details.
21
22  *******************************************************************/
23
24 #ifndef _UL_LOGBASE_H
25 #define _UL_LOGBASE_H
26
27 #include <stdarg.h>
28 #include "ul_utdefs.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #define UL_LOGL_MASK (0xff)
35 #define UL_LOGL_CONT (0x1000)
36
37 #define UL_LOGL_FATAL   1
38 #define UL_LOGL_ERR     2
39 #define UL_LOGL_MSG     3
40 #define UL_LOGL_INF     4
41 #define UL_LOGL_DEB     5
42 #define UL_LOGL_TRASH   6
43
44 #ifndef UL_LOGL_MAX
45 #define UL_LOGL_MAX     6
46 #endif
47
48 /**
49  * struct ul_log_domain - Loggomg domain structure
50  * @level:      maximal enabled logging level for domain
51  * @name:       logging domain name
52  * @flags:      logging domain flags
53  */
54 typedef struct ul_log_domain {
55   int level;
56   const char *name;
57   int flags;
58 } ul_log_domain_t;
59
60 typedef void (ul_log_fnc_t)(ul_log_domain_t *domain, int level,
61         const char *format, va_list ap);
62
63 void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags);
64
65 int ul_log_check_default_output(void);
66
67 void ul_vlog1(ul_log_domain_t *domain, int level,
68         const char *format, va_list ap);
69
70 void ul_log1(ul_log_domain_t *domain, int level,
71         const char *format, ...) UL_ATTR_PRINTF (3, 4);
72
73 #ifdef UL_LOG_NOINLINE
74
75 int ul_log_cond(ul_log_domain_t *domain, int level);
76
77 void ul_vlog(ul_log_domain_t *domain, int level,
78         const char *format, va_list ap);
79
80 void ul_log(ul_log_domain_t *domain, int level,
81         const char *format, ...) UL_ATTR_PRINTF (3, 4);
82
83 #else /*UL_LOG_NOINLINE*/
84
85 static inline
86 int ul_log_cond(ul_log_domain_t *domain, int level)
87 {
88   if(!domain || (level > UL_LOGL_MAX))
89     return 0;
90   return level <= domain->level;
91 }
92
93 static inline
94 void ul_vlog(ul_log_domain_t *domain, int level,
95         const char *format, va_list ap)
96 {
97   if(!ul_log_cond(domain,level))
98     return;
99   ul_vlog1(domain, level, format, ap);
100 }
101
102 static inline
103 void ul_log(ul_log_domain_t *domain, int level,
104         const char *format, ...) UL_ATTR_PRINTF (3, 4);
105
106 static inline
107 void ul_log(ul_log_domain_t *domain, int level,
108         const char *format, ...)
109 {
110   va_list ap;
111
112   if(!ul_log_cond(domain,level))
113     return;
114   va_start (ap, format);
115   ul_vlog1(domain, level, format, ap);
116   va_end (ap);
117 }
118
119 #endif /*UL_LOG_NOINLINE*/
120
121 #ifdef __cplusplus
122 } /* extern "C"*/
123 #endif
124
125 #endif /*_UL_LOGBASE_H*/