YAZ  5.23.1
log.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Index Data nor the names of its contributors
13  * may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
33 #ifndef YAZ_LOG_H
34 #define YAZ_LOG_H
35 
36 #include <stdio.h>
37 #include <yaz/yconfig.h>
38 
40 
42 #define YLOG_FATAL 0x00000001
43 
44 #define YLOG_DEBUG 0x00000002
45 
46 #define YLOG_WARN 0x00000004
47 
48 #define YLOG_LOG 0x00000008
49 
50 #define YLOG_ERRNO 0x00000010
51 
52 #define YLOG_TID 0x00000020
53 
54 #define YLOG_APP 0x00000040
55 
56 #define YLOG_MALLOC 0x00000080
57 
58 #define YLOG_NOTIME 0x00000100
59 
60 #define YLOG_APP2 0x00000200
61 
62 #define YLOG_APP3 0x00000400
63 
64 #define YLOG_FLUSH 0x00000800
65 
66 #define YLOG_LOGLVL 0x00001000 /* log when modules query log levels */
67  /* this has to be a hard-coded bit, not to loop*/
68 
69 #define YLOG_ALL (0xffff&~YLOG_MALLOC&~YLOG_NOTIME)
70 
72 #define YLOG_DEFAULT_LEVEL \
73  (YLOG_FATAL | YLOG_ERRNO | YLOG_LOG | YLOG_WARN | YLOG_FLUSH)
74 /* not having flush here confuses Solaris users, who won't see any logs until
75  * (and if) the program exits normally */
76 
78 #define YLOG_LAST_BIT YLOG_LOGLVL
79 
87 YAZ_EXPORT void yaz_log_init(int level, const char *prefix, const char *fname);
88 
97 YAZ_EXPORT void yaz_log_init_file(const char *fname);
98 
102 YAZ_EXPORT void yaz_log_init_level(int level);
103 
107 YAZ_EXPORT void yaz_log_init_prefix(const char *prefix);
108 
112 YAZ_EXPORT void yaz_log_init_prefix2(const char *prefix);
113 
122 YAZ_EXPORT void yaz_log_time_format(const char *fmt);
123 
130 YAZ_EXPORT void yaz_log_init_max_size(int mx);
131 
140 YAZ_EXPORT void yaz_log(int level, const char *fmt, ...)
141 #ifdef __GNUC__
142  __attribute__ ((format (printf, 2, 3)))
143 #endif
144  ;
145 
156 YAZ_EXPORT int yaz_log_mask_str(const char *str);
157 
166 YAZ_EXPORT int yaz_log_mask_str_x(const char *str, int level);
167 
178 YAZ_EXPORT int yaz_log_module_level(const char *name);
179 
184 YAZ_EXPORT FILE *yaz_log_file(void);
185 
193 YAZ_EXPORT void yaz_log_set_handler(void (*func)(int, const char *,
194  void *), void *info);
195 
198 YAZ_EXPORT void yaz_log_reopen(void);
199 
201 YAZ_EXPORT void yaz_log_trunc(void);
202 
207 YAZ_EXPORT void log_event_start(void (*func)(int level, const char *msg,
208  void *info), void *info);
209 
214 YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg,
215  void *info), void *info);
216 
221 YAZ_EXPORT void yaz_log_xml_errors(const char *prefix, int log_level);
222 
225 YAZ_EXPORT void yaz_log_lock(void);
226 
229 YAZ_EXPORT void yaz_log_unlock(void);
231 
232 #endif
233 /*
234  * Local variables:
235  * c-basic-offset: 4
236  * c-file-style: "Stroustrup"
237  * indent-tabs-mode: nil
238  * End:
239  * vim: shiftwidth=4 tabstop=8 expandtab
240  */
241 
void log_event_end(void(*func)(int level, const char *msg, void *info), void *info)
installs hook to be called after each log msg
void yaz_log_init_level(int level)
sets log level
Definition: log.c:226
void log_event_start(void(*func)(int level, const char *msg, void *info), void *info)
installs hook to be called before each log msg
void yaz_log_reopen(void)
reopen current log file (unless disabled or stderr)
Definition: log.c:389
void yaz_log_xml_errors(const char *prefix, int log_level)
Makes Libxml2 and Libxslt log errors through yaz_log.
Definition: xmlerror.c:47
#define YAZ_END_CDECL
Definition: yconfig.h:57
char * name
Definition: initopt.c:18
static int log_level
Definition: eventl.c:39
FILE * yaz_log_file(void)
returns FILE handle for log or NULL if no file is in use
Definition: log.c:136
void yaz_log_init(int level, const char *prefix, const char *fname)
sets level, prefix and filename for logging
Definition: log.c:279
int yaz_log_module_level(const char *name)
returns level for module
Definition: log.c:584
int yaz_log_mask_str(const char *str)
converts log level string to log level (integer)
Definition: log.c:604
void yaz_log_init_max_size(int mx)
sets limit in bytes for size for log file
Definition: log.c:288
int yaz_log_mask_str_x(const char *str, int level)
converts log level string to log level with "start" level
Definition: log.c:612
Header with fundamental macros.
void yaz_log_set_handler(void(*func)(int, const char *, void *), void *info)
sets custom log handler
Definition: log.c:296
void yaz_log_init_file(const char *fname)
sets log file
Definition: log.c:166
void yaz_log_time_format(const char *fmt)
sets time format for log mesages
Definition: log.c:527
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition: log.c:485
void yaz_log_init_prefix2(const char *prefix)
sets second log message prefix
Definition: log.c:270
void yaz_log_init_prefix(const char *prefix)
sets log message prefix
Definition: log.c:261
void yaz_log_unlock(void)
Unlock for YAZ log writes.
Definition: log.c:117
void yaz_log_lock(void)
Lock for YAZ log writes.
Definition: log.c:112
void yaz_log_trunc(void)
Truncate the log file.
Definition: log.c:399
#define YAZ_BEGIN_CDECL
Definition: yconfig.h:56