b17c4ae08c36d0e234b04592d2d76f7060bec6f2
[yaz-moved-to-github.git] / include / yaz / log.h
1 /*
2  * Copyright (c) 1995-2003, Index Data.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation, in whole or in part, for any purpose, is hereby granted,
6  * provided that:
7  *
8  * 1. This copyright and permission notice appear in all copies of the
9  * software and its documentation. Notices of copyright or attribution
10  * which appear at the beginning of any file must remain unchanged.
11  *
12  * 2. The name of Index Data or the individual authors may not be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22  * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  *
26  * $Id: log.h,v 1.12 2003-10-09 15:51:36 adam Exp $
27  */
28
29 #ifndef LOG_H
30 #define LOG_H
31
32 #include <stdio.h>
33 #include <yaz/yconfig.h>
34 #include <yaz/xmalloc.h>
35
36 YAZ_BEGIN_CDECL
37
38 #define LOG_FATAL  0x0001
39 #define LOG_DEBUG  0x0002
40 #define LOG_WARN   0x0004
41 #define LOG_LOG    0x0008
42 #define LOG_ERRNO  0x0010     /* append strerror to message */
43 #define LOG_FILE   0x0020
44 #define LOG_APP    0x0040     /* For application level events such as new-connection */
45 #define LOG_MALLOC 0x0080     /* debugging mallocs */
46 #define LOG_NOTIME 0x0100     /* do not output date and time */
47 #define LOG_APP2   0x0200     /* For application-level events, such as api calls */
48 #define LOG_APP3   0x0400     /* For more application-level events */
49
50 #define LOG_ALL   (0xffff&~LOG_MALLOC&~LOG_NOTIME)
51
52 #define LOG_DEFAULT_LEVEL (LOG_FATAL | LOG_ERRNO | LOG_LOG | LOG_WARN)
53
54 #define logf yaz_log
55
56 YAZ_EXPORT void yaz_log_init(int level, const char *prefix, const char *name);
57 YAZ_EXPORT void yaz_log_init_file (const char *fname);
58 YAZ_EXPORT void yaz_log_init_level (int level);
59 YAZ_EXPORT void yaz_log_init_prefix (const char *prefix);
60 YAZ_EXPORT void yaz_log_init_prefix2 (const char *prefix);
61
62 YAZ_EXPORT void yaz_log(int level, const char *fmt, ...)
63 #ifdef __GNUC__
64         __attribute__ ((format (printf, 2, 3)))
65 #endif
66         ;
67 YAZ_EXPORT int yaz_log_mask_str (const char *str);
68 YAZ_EXPORT int yaz_log_mask_str_x (const char *str, int level);
69 YAZ_EXPORT FILE *yaz_log_file(void);
70
71 YAZ_EXPORT void log_event_start (void (*func)(int level, const char *msg, void *info),
72         void *info);
73 YAZ_EXPORT void log_event_end (void (*func)(int level, const char *msg, void *info),
74         void *info);
75
76 YAZ_EXPORT void yaz_log_reopen(void);
77 YAZ_END_CDECL
78
79 #endif