]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_logbase.h
added support for logging, conditional compilation of ulcintf
[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 #define UL_LOGL_MASK (0xff)
31 #define UL_LOGL_CONT (0x1000)
32
33 #define UL_LOGL_FATAL   1
34 #define UL_LOGL_ERR     2
35 #define UL_LOGL_MSG     3
36 #define UL_LOGL_INF     4
37 #define UL_LOGL_DEB     5
38 #define UL_LOGL_TRASH   6
39
40 #ifndef UL_LOGL_MAX
41 #define UL_LOGL_MAX     6
42 #endif
43
44 /**
45  * struct ul_log_domain - Loggomg domain structure
46  * @level:      maximal enabled logging level for domain
47  * @name:       logging domain name
48  * @flags:      logging domain flags
49  */
50 typedef struct ul_log_domain {
51   int level;
52   const char *name;
53   int flags;
54 } ul_log_domain_t;
55
56 typedef void (ul_log_fnc_t)(ul_log_domain_t *domain, int level,
57         const char *format, va_list ap);
58
59 void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags);
60
61 void ul_vlog1(ul_log_domain_t *domain, int level,
62         const char *format, va_list ap);
63
64 void ul_log1(ul_log_domain_t *domain, int level,
65         const char *format, ...) UL_ATTR_PRINTF (3, 4);
66
67 #ifdef UL_LOG_NOINLINE
68
69 int ul_log_cond(ul_log_domain_t *domain, int level);
70
71 void ul_vlog(ul_log_domain_t *domain, int level,
72         const char *format, va_list ap);
73
74 void ul_log(ul_log_domain_t *domain, int level,
75         const char *format, ...) UL_ATTR_PRINTF (3, 4);
76
77 #else /*UL_LOG_NOINLINE*/
78
79 static inline
80 int ul_log_cond(ul_log_domain_t *domain, int level)
81 {
82   if(!domain || (level > UL_LOGL_MAX))
83     return 0;
84   return level <= domain->level;
85 }
86
87 static inline
88 void ul_vlog(ul_log_domain_t *domain, int level,
89         const char *format, va_list ap)
90 {
91   if(!ul_log_cond(domain,level))
92     return;
93   ul_vlog1(domain, level, format, ap);
94 }
95
96 static inline
97 void ul_log(ul_log_domain_t *domain, int level,
98         const char *format, ...) UL_ATTR_PRINTF (3, 4);
99
100 static inline
101 void ul_log(ul_log_domain_t *domain, int level,
102         const char *format, ...)
103 {
104   va_list ap;
105
106   if(!ul_log_cond(domain,level))
107     return;
108   va_start (ap, format);
109   ul_vlog1(domain, level, format, ap);
110   va_end (ap);
111 }
112
113 #endif /*UL_LOG_NOINLINE*/
114
115 #endif /*_UL_LOGBASE_H*/