updates.
[silc.git] / lib / silcutil / silclog.h
1 /*
2
3   silclog.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef SILCLOG_H
22 #define SILCLOG_H
23
24 /* Set TRUE/FALSE to enable/disable debugging */
25 extern int silc_debug;
26 extern char *silc_debug_string;
27
28 /* SILC Log types */
29 typedef enum {
30   SILC_LOG_INFO,
31   SILC_LOG_WARNING,
32   SILC_LOG_ERROR,
33   SILC_LOG_FATAL
34 } SilcLogType;
35
36 /* Log type name structure. */
37 typedef struct {
38   char *name;
39   SilcLogType type;
40 } SilcLogTypeName;
41
42 /* Log function callback. */
43 typedef void (*SilcLogCb)(char *message);
44
45 /* Debug function callback. */
46 typedef void (*SilcDebugCb)(char *file, char *function, 
47                             int line, char *message);
48
49 /* Debug hexdump function callback. */
50 typedef void (*SilcDebugHexdumpCb)(char *file, char *function, 
51                                    int line, unsigned char *data,
52                                    uint32 data_len, char *message);
53
54 /* Default log filenames */
55 #define SILC_LOG_FILE_INFO "silcd.log"
56 #define SILC_LOG_FILE_WARNING "silcd_error.log"
57 #define SILC_LOG_FILE_ERROR SILC_LOG_FILE_WARNING
58 #define SILC_LOG_FILE_FATAL SILC_LOG_FILE_WARNING
59
60 /* Log files. Set by silc_log_set_logfiles. */
61 extern char *log_info_file;
62 extern char *log_warning_file;
63 extern char *log_error_file;
64 extern char *log_fatal_file;
65 extern uint32 log_info_size;
66 extern uint32 log_warning_size;
67 extern uint32 log_error_size;
68 extern uint32 log_fatal_size;
69
70 #ifdef WIN32
71 #define __FUNCTION__ ""
72 #endif
73
74 /* Log macros. */
75 #define SILC_LOG_INFO(fmt) (silc_log_output(log_info_file, \
76                                            log_info_size, \
77                                            SILC_LOG_INFO, \
78                                            silc_format fmt))
79 #define SILC_LOG_WARNING(fmt) (silc_log_output(log_warning_file, \
80                                                log_warning_size, \
81                                                SILC_LOG_WARNING, \
82                                                silc_format fmt))
83 #define SILC_LOG_ERROR(fmt) (silc_log_output(log_error_file, \
84                                              log_error_size, \
85                                              SILC_LOG_ERROR, \
86                                              silc_format fmt))
87 #define SILC_LOG_FATAL(fmt) (silc_log_output(log_fatal_file, \
88                                              log_fatal_size, \
89                                              SILC_LOG_FATAL, \
90                                              silc_format fmt))
91
92 /* Debug macro is a bit different from other logging macros and it
93    is compiled in only if debugging is enabled. */
94 #ifdef SILC_DEBUG
95 #define SILC_LOG_DEBUG(fmt) (silc_log_output_debug(__FILE__, \
96                                                    __FUNCTION__, \
97                                                    __LINE__, \
98                                                    silc_format fmt))
99 #define SILC_LOG_HEXDUMP(fmt, data, len) \
100   (silc_log_output_hexdump(__FILE__, \
101                            __FUNCTION__, \
102                            __LINE__, \
103                            (data), (len), \
104                            silc_format fmt))
105 #else
106 #define SILC_LOG_DEBUG(fmt)
107 #define SILC_LOG_HEXDUMP(fmt, data, len)
108 #endif
109
110 /* Prototypes */
111 void silc_log_output_debug(char *file, char *function, 
112                            int line, char *string);
113 void silc_log_output(const char *filename, uint32 maxsize,
114                      SilcLogType type, char *string);
115 void silc_log_output_hexdump(char *file, char *function, 
116                              int line, void *data_in,
117                              uint32 len, char *string);
118 void silc_log_set_files(char *info, uint32 info_size, 
119                         char *warning, uint32 warning_size,
120                         char *error, uint32 error_size,
121                         char *fatal, uint32 fatal_size);
122 void silc_log_set_callbacks(SilcLogCb info, SilcLogCb warning,
123                             SilcLogCb error, SilcLogCb fatal);
124 void silc_log_reset_callbacks();
125 void silc_log_set_debug_callbacks(SilcDebugCb debug, 
126                                   SilcDebugHexdumpCb debug_hexdump);
127 void silc_log_reset_debug_callbacks();
128 void silc_log_set_debug_string(const char *debug_string);
129
130 #endif