1 #ifndef _ATALK_LOGGER_H
2 #define _ATALK_LOGGER_H 1
5 * logger LOG Macro Usage
6 * ======================
8 * LOG(<logtype>, <loglevel>, "<string>"[, args]);
17 * setuplog(char *confstring)
18 * confstring = "<logtype> <loglevel> [<filename>]"
20 * Calling without <filename> configures basic logging to syslog. Specifying <filename>
21 * configures extended logging to <filename>.
23 * You can later disable logging by calling
25 * unsetuplog(char *confstring)
26 * confstring = "<logtype> [<any_string>]"
28 * Calling without <any_string> disables syslog logging, calling with <any_string>
29 * disables file logging.
32 * you can setup a default with "Default". Any other logtype used in LOG will then
33 * use the default if not setup itself. This is probabyl the only thing you may
37 * setuplog("default log_debug /var/log/debug.log");
38 * See also libatalk/util/test/logger_test.c
43 * Some netatalk daemons (31.3.2009.: e.g. atalkd, papd) may not be converted to
44 * use the new API and might still call
46 * syslog_setup(int loglevel, enum logtypes logtype, int display_options, int facility);
48 * directly. These daemons are therefore limited to syslog logging. Also their
49 * loglevel can't be changed at runtime.
53 * dont get confused by log_init(). It only gets called if your app
54 * forgets to setup logging before calling LOG.
61 #include <atalk/boolean.h>
67 #define MAXLOGSIZE 512
89 #define log_maxdebug -1
93 #define LOGLEVEL_STRING_IDENTIFIERS { \
107 /* this is the enum specifying all availiable logtypes */
118 logtype_end_of_list_marker /* don't put any logtypes after this */
121 /* these are the string identifiers corresponding to each logtype */
122 #define LOGTYPE_STRING_IDENTIFIERS { \
132 "end_of_list_marker"} \
134 /* Display Option flags. */
135 /* redefine these so they can don't interfeer with syslog */
136 /* these can be used in standard logging too */
137 #define logoption_nsrcinfo 0x04 /* don't log source info */
138 /* the following do not work anymore, they're only provided in order to not
139 * break existing source code */
140 #define logoption_pid 0x01 /* log the pid with each message */
141 #define logoption_cons 0x02 /* log on the console if error logging */
142 #define logoption_ndelay 0x08 /* don't delay open */
143 #define logoption_perror 0x20 /* log to stderr as well */
144 #define logoption_nfile 0x40 /* ignore the file that called the log */
145 #define logoption_nline 0x80 /* ignore the line that called the log*/
148 /* redefine these so they can don't interfeer with syslog */
149 #define logfacility_user (1<<3) /* random user-level messages */
150 #define logfacility_mail (2<<3) /* mail system */
151 #define logfacility_daemon (3<<3) /* system daemons */
152 #define logfacility_auth (4<<3) /* security/authorization messages */
153 #define logfacility_syslog (5<<3) /* messages generated by syslogd */
154 #define logfacility_lpr (6<<3) /* line printer subsystem */
155 #define logfacility_authpriv (10<<3) /* security/auth messages (private) */
156 #define logfacility_ftp (11<<3) /* ftp daemon */
158 /* =========================================================================
159 Structure definitions
160 ========================================================================= */
162 /* Main log config */
164 int inited; /* file log config initialized ? */
165 int filelogging; /* Any level set to filelogging ? */
166 /* Deactivates syslog logging */
167 char processname[16];
168 int syslog_opened; /* syslog opened ? */
169 int facility; /* syslog facility to use */
170 int syslog_display_options;
171 int syslog_level; /* Log Level to send to syslog */
174 /* This stores the config and options for one filelog type (e.g. logger, afpd etc.) */
176 int set; /* set individually ? yes: changing default
177 * doesnt change it. no: it changes it.*/
178 char *filename; /* Name of file */
179 int fd; /* logfiles fd */
180 int level; /* Log Level to put in this file */
184 /* =========================================================================
186 ========================================================================= */
189 /* Make config accessible for LOG macro */
190 extern log_config_t log_config;
191 extern filelog_conf_t file_configs[logtype_end_of_list_marker];
193 /* These are used by the LOG macro to store __FILE__ and __LINE__ */
194 extern char *log_src_filename;
195 extern int log_src_linenumber;
198 /* =========================================================================
199 Global function decarations
200 ========================================================================= */
205 /* Setup the level and type of log that will be logged for file loggging */
206 void log_setup(const char *filename, enum loglevels loglevel, enum logtypes logtype);
208 /* Setup the level and type of log that will be logged to syslog. */
209 void syslog_setup(int loglevel, enum logtypes logtype,
210 int display_options, int facility);
212 /* This gets called e.g. from afpd.conf parsing code with a string like: */
213 /* "default log_maxdebug /var/log/afpd.log" */
214 void setuplog(const char *logstr);
216 /* This gets called e.g. from afpd.conf parsing code with a string like: */
217 /* "default dummyname" */
218 void unsetuplog(const char *logstr);
220 /* finish up and close the logs */
221 void log_close(void);
223 /* This function sets up the ProcessName */
224 void set_processname(const char *processname);
227 * How to write a LOG macro:
228 * http://c-faq.com/cpp/debugmacs.html
230 * We choose the verbose form in favor of the obfuscated ones, its easier
231 * to parse for human beings and facilitates expanding the macro for
232 * inline checks for debug levels.
234 * How to properly enclose multistatement macros:
235 * http://en.wikipedia.org/wiki/C_macro#Multiple_statements
238 /* LOG macro func no.1: log the message to file */
239 void make_log_entry(enum loglevels loglevel, enum logtypes logtype, char *message, ...);
241 /* LOG macro func no.2: log the message to syslog */
242 void make_syslog_entry(enum loglevels loglevel, enum logtypes logtype, char *message, ...);
246 any configured file-logging deactivates syslog logging
248 #define LOG(log_level, type, ...) \
252 if ( ! log_config.inited) \
254 if (file_configs[(type)].level >= (log_level)) \
255 log_src_filename = __FILE__, \
256 log_src_linenumber = __LINE__, \
257 make_log_entry((log_level), (type), __VA_ARGS__); \
258 else if (( ! log_config.filelogging) && (log_config.syslog_level >= (log_level))) \
259 make_syslog_entry((log_level), (type), __VA_ARGS__); \
261 #endif /* _ATALK_LOGGER_H */