Initial revision
[crypto.git] / lib / silccore / 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 /* SILC Log types */
25 typedef enum {
26   SILC_LOG_INFO,
27   SILC_LOG_WARNING,
28   SILC_LOG_ERROR,
29   SILC_LOG_FATAL
30 } SilcLogType;
31
32 /* Log type name structure. */
33 typedef struct {
34   char *name;
35   SilcLogType type;
36 } SilcLogTypeName;
37
38 /* Default log filenames */
39 #define SILC_LOG_FILE_INFO "silcd.log"
40 #define SILC_LOG_FILE_WARNING "silcd_error.log"
41 #define SILC_LOG_FILE_ERROR SILC_LOG_FILE_WARNING
42 #define SILC_LOG_FILE_FATAL SILC_LOG_FILE_WARNING
43
44 /* Log files. Set by silc_log_set_logfiles. */
45 extern char *log_info_file;
46 extern char *log_warning_file;
47 extern char *log_error_file;
48 extern char *log_fatal_file;
49 extern unsigned int log_info_size;
50 extern unsigned int log_warning_size;
51 extern unsigned int log_error_size;
52 extern unsigned int log_fatal_size;
53
54 /* Log macros. */
55 #define SILC_LOG_INFO(fmt) silc_log_output(log_info_file, \
56                                            log_info_size, \
57                                            SILC_LOG_INFO, \
58                                            silc_log_format fmt)) 
59 #define SILC_LOG_WARNING(fmt) (silc_log_output(log_warning_file, \
60                                                log_warning_size, \
61                                                SILC_LOG_WARNING, \
62                                                silc_log_format fmt))
63 #define SILC_LOG_ERROR(fmt) (silc_log_output(log_error_file, \
64                                              log_error_size, \
65                                              SILC_LOG_ERROR, \
66                                              silc_log_format fmt))
67 #define SILC_LOG_FATAL(fmt) (silc_log_output(log_fatal_file, \
68                                              log_fatal_size, \
69                                              SILC_LOG_FATAL, \
70                                              silc_log_format fmt))
71
72 /* Debug macro is a bit different from other logging macros and it
73    is compiled in only if debugging is enabled. */
74 #ifdef SILC_DEBUG
75 #define SILC_LOG_DEBUG(fmt) (silc_log_output_debug(__FILE__, \
76                                                    __FUNCTION__, \
77                                                    __LINE__, \
78                                                    silc_log_format fmt))
79 #define SILC_LOG_HEXDUMP(fmt, data, len) \
80   (silc_log_output_hexdump(__FILE__, \
81                            __FUNCTION__, \
82                            __LINE__, \
83                            (data), (len), \
84                            silc_log_format fmt))
85 #else
86 #define SILC_LOG_DEBUG(fmt)
87 #define SILC_LOG_HEXDUMP(fmt, data, len)
88 #endif
89
90 /* Prototypes */
91 char *silc_log_format(char *fmt, ...);
92 void silc_log_output_debug(char *file, char *function, 
93                            int line, char *string);
94 void silc_log_output(const char *filename, unsigned int maxsize,
95                      SilcLogType type, char *string);
96 void silc_log_output_hexdump(char *file, char *function, 
97                              int line, void *data_in,
98                              unsigned int len, char *string);
99 void silc_log_set_files(char *info, unsigned int info_size, 
100                         char *warning, unsigned int warning_size,
101                         char *error, unsigned int error_size,
102                         char *fatal, unsigned int fatal_size);
103
104 #endif