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 bool silc_debug;
26 extern bool silc_debug_hexdump;
27 extern char *silc_debug_string;
28
29 /* SILC Log types */
30 typedef enum {
31   SILC_LOG_INFO,
32   SILC_LOG_WARNING,
33   SILC_LOG_ERROR,
34   SILC_LOG_FATAL
35 } SilcLogType;
36
37 /* Log type name structure. */
38 typedef struct {
39   char *name;
40   SilcLogType type;
41 } SilcLogTypeName;
42
43 /* Log function callback. */
44 typedef void (*SilcLogCb)(char *message);
45
46 /* Debug function callback. */
47 typedef void (*SilcDebugCb)(char *file, char *function, 
48                             int line, char *message);
49
50 /* Debug hexdump function callback. */
51 typedef void (*SilcDebugHexdumpCb)(char *file, char *function, 
52                                    int line, unsigned char *data,
53                                    uint32 data_len, char *message);
54
55 /* Default log filenames */
56 #define SILC_LOG_FILE_INFO "silcd.log"
57 #define SILC_LOG_FILE_WARNING "silcd_error.log"
58 #define SILC_LOG_FILE_ERROR SILC_LOG_FILE_WARNING
59 #define SILC_LOG_FILE_FATAL SILC_LOG_FILE_WARNING
60
61 /* Log files. Set by silc_log_set_logfiles. */
62 extern char *log_info_file;
63 extern char *log_warning_file;
64 extern char *log_error_file;
65 extern char *log_fatal_file;
66 extern uint32 log_info_size;
67 extern uint32 log_warning_size;
68 extern uint32 log_error_size;
69 extern uint32 log_fatal_size;
70
71 #ifdef WIN32
72 #define __FUNCTION__ ""
73 #endif
74
75 /* Log macros. */
76 #define SILC_LOG_INFO(fmt) (silc_log_output(log_info_file, \
77                                            log_info_size, \
78                                            SILC_LOG_INFO, \
79                                            silc_format fmt))
80 #define SILC_LOG_WARNING(fmt) (silc_log_output(log_warning_file, \
81                                                log_warning_size, \
82                                                SILC_LOG_WARNING, \
83                                                silc_format fmt))
84 #define SILC_LOG_ERROR(fmt) (silc_log_output(log_error_file, \
85                                              log_error_size, \
86                                              SILC_LOG_ERROR, \
87                                              silc_format fmt))
88 #define SILC_LOG_FATAL(fmt) (silc_log_output(log_fatal_file, \
89                                              log_fatal_size, \
90                                              SILC_LOG_FATAL, \
91                                              silc_format fmt))
92
93 /* Debug macro is a bit different from other logging macros and it
94    is compiled in only if debugging is enabled. */
95 #ifdef SILC_DEBUG
96 #define SILC_LOG_DEBUG(fmt) (silc_log_output_debug(__FILE__, \
97                                                    __FUNCTION__, \
98                                                    __LINE__, \
99                                                    silc_format fmt))
100 #define SILC_LOG_HEXDUMP(fmt, data, len) \
101   (silc_log_output_hexdump(__FILE__, \
102                            __FUNCTION__, \
103                            __LINE__, \
104                            (data), (len), \
105                            silc_format fmt))
106 #else
107 #define SILC_LOG_DEBUG(fmt)
108 #define SILC_LOG_HEXDUMP(fmt, data, len)
109 #endif
110
111 /* Prototypes */
112 void silc_log_output_debug(char *file, char *function, 
113                            int line, char *string);
114 void silc_log_output(const char *filename, uint32 maxsize,
115                      SilcLogType type, char *string);
116 void silc_log_output_hexdump(char *file, char *function, 
117                              int line, void *data_in,
118                              uint32 len, char *string);
119 void silc_log_set_files(char *info, uint32 info_size, 
120                         char *warning, uint32 warning_size,
121                         char *error, uint32 error_size,
122                         char *fatal, uint32 fatal_size);
123 void silc_log_set_callbacks(SilcLogCb info, SilcLogCb warning,
124                             SilcLogCb error, SilcLogCb fatal);
125 void silc_log_reset_callbacks();
126 void silc_log_set_debug_callbacks(SilcDebugCb debug, 
127                                   SilcDebugHexdumpCb debug_hexdump);
128 void silc_log_reset_debug_callbacks();
129 void silc_log_set_debug_string(const char *debug_string);
130
131 #endif