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