1 #ifndef _ATALK_LOGGER_H
2 #define _ATALK_LOGGER_H 1
7 #include <atalk/boolean.h>
13 #define MAXLOGSIZE 512
29 #define LOGLEVEL_STRING_IDENTIFIERS { \
43 /* this is the enum specifying all availiable logtypes */
54 logtype_end_of_list_marker /* don't put any logtypes after this */
57 /* these are the string identifiers corresponding to each logtype */
58 #define LOGTYPE_STRING_IDENTIFIERS { \
68 "end_of_list_marker"} \
70 /* Display Option flags. */
71 /* redefine these so they can don't interfeer with syslog */
72 /* these can be used in standard logging too */
73 #define logoption_nsrcinfo 0x04 /* don't log source info */
74 /* the following do not work anymore, they're only provided in order to not
75 * break existing source code */
76 #define logoption_pid 0x01 /* log the pid with each message */
77 #define logoption_cons 0x02 /* log on the console if error logging */
78 #define logoption_ndelay 0x08 /* don't delay open */
79 #define logoption_perror 0x20 /* log to stderr as well */
80 #define logoption_nfile 0x40 /* ignore the file that called the log */
81 #define logoption_nline 0x80 /* ignore the line that called the log*/
84 /* redefine these so they can don't interfeer with syslog */
85 #define logfacility_user (1<<3) /* random user-level messages */
86 #define logfacility_mail (2<<3) /* mail system */
87 #define logfacility_daemon (3<<3) /* system daemons */
88 #define logfacility_auth (4<<3) /* security/authorization messages */
89 #define logfacility_syslog (5<<3) /* messages generated by syslogd */
90 #define logfacility_lpr (6<<3) /* line printer subsystem */
91 #define logfacility_authpriv (10<<3) /* security/auth messages (private) */
92 #define logfacility_ftp (11<<3) /* ftp daemon */
94 /* =========================================================================
96 ========================================================================= */
100 int inited; /* file log config initialized ? */
101 int filelogging; /* Any level set to filelogging ? */
102 /* Deactivates syslog logging */
103 char processname[16];
104 int syslog_opened; /* syslog opened ? */
105 int facility; /* syslog facility to use */
106 int syslog_display_options;
107 int syslog_level; /* Log Level to send to syslog */
110 /* This stores the config and options for one filelog type (e.g. logger, afpd etc.) */
112 int set; /* set individually ? yes: changing default
113 * doesnt change it. no: it changes it.*/
114 char *filename; /* Name of file */
115 int fd; /* logfiles fd */
116 int level; /* Log Level to put in this file */
120 /* =========================================================================
122 ========================================================================= */
125 /* Make config accessible for LOG macro */
126 extern log_config_t log_config;
127 extern filelog_conf_t file_configs[logtype_end_of_list_marker];
129 /* These are used by the LOG macro to store __FILE__ and __LINE__ */
130 extern char *log_src_filename;
131 extern int log_src_linenumber;
134 /* =========================================================================
135 Global function decarations
136 ========================================================================= */
141 /* Setup the level and type of log that will be logged for file loggging */
142 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype);
144 /* Setup the level and type of log that will be logged to syslog. */
145 //void syslog_setup(enum loglevels loglevel);
146 void syslog_setup(int loglevel, enum logtypes logtype,
147 int display_options, int facility);
149 /* void setuplog(char *logsource, char *logtype, char *loglevel, char *filename); */
150 void setuplog(char *logtype, char *loglevel, char *filename);
152 /* finish up and close the logs */
155 /* This function sets up the ProcessName */
156 void set_processname(char *processname);
159 * How to write a LOG macro:
160 * http://c-faq.com/cpp/debugmacs.html
162 * We choose the verbose form in favor of the obfuscated ones, its easier
163 * to parse for human beings and facilitates expanding the macro for
164 * inline checks for debug levels.
166 * How to properly enclose multistatement macros:
167 * http://en.wikipedia.org/wiki/C_macro#Multiple_statements
170 /* LOG macro func no.1: log the message to file */
171 void make_log_entry(enum loglevels loglevel, enum logtypes logtype, char *message, ...);
173 /* LOG macro func no.2: log the message to syslog */
174 void make_syslog_entry(enum loglevels loglevel, enum logtypes logtype, char *message, ...);
178 any configured file-logging deactivates syslog logging
181 #define LOG(a,b, ...) \
183 if ( ! log_config.inited) \
185 if (file_configs[b].level >= a) \
186 log_src_filename = __FILE__, \
187 log_src_linenumber = __LINE__, \
188 make_log_entry(a, b, __VA_ARGS__); \
189 else if (( ! log_config.filelogging) && (log_config.syslog_level >= a)) \
190 make_syslog_entry(a, b, __VA_ARGS__); \
192 #endif /* _ATALK_LOGGER_H */