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 /* logger is used by pam modules */
68 #ifndef UAM_MODULE_EXPORT
69 #define UAM_MODULE_EXPORT
87 /* this is the enum specifying all availiable logtypes */
98 logtype_end_of_list_marker /* don't put any logtypes after this */
102 /* Display Option flags. */
103 /* redefine these so they can don't interfeer with syslog */
104 /* these can be used in standard logging too */
105 #define logoption_nsrcinfo 0x04 /* don't log source info */
106 /* the following do not work anymore, they're only provided in order to not
107 * break existing source code */
108 #define logoption_pid 0x01 /* log the pid with each message */
109 #define logoption_cons 0x02 /* log on the console if error logging */
110 #define logoption_ndelay 0x08 /* don't delay open */
111 #define logoption_perror 0x20 /* log to stderr as well */
112 #define logoption_nfile 0x40 /* ignore the file that called the log */
113 #define logoption_nline 0x80 /* ignore the line that called the log*/
116 /* redefine these so they can don't interfeer with syslog */
117 #define logfacility_user (1<<3) /* random user-level messages */
118 #define logfacility_mail (2<<3) /* mail system */
119 #define logfacility_daemon (3<<3) /* system daemons */
120 #define logfacility_auth (4<<3) /* security/authorization messages */
121 #define logfacility_syslog (5<<3) /* messages generated by syslogd */
122 #define logfacility_lpr (6<<3) /* line printer subsystem */
123 #define logfacility_authpriv (10<<3) /* security/auth messages (private) */
124 #define logfacility_ftp (11<<3) /* ftp daemon */
126 /* =========================================================================
127 Structure definitions
128 ========================================================================= */
130 /* Main log config */
132 bool inited; /* file log config initialized ? */
133 bool syslog_opened; /* syslog opened ? */
134 bool console; /* if logging to console from a cli util */
135 char processname[16];
137 int syslog_display_options;
140 /* This stores the config and options for one filelog type (e.g. logger, afpd etc.) */
142 bool set; /* set individually ? yes: changing default
143 * doesnt change it. no: it changes it.*/
144 bool syslog; /* This type logs to syslog */
145 int fd; /* logfiles fd */
146 enum loglevels level; /* Log Level to put in this file */
151 /* =========================================================================
153 ========================================================================= */
155 /* Make config accessible for LOG macro */
156 extern log_config_t log_config;
158 extern UAM_MODULE_EXPORT logtype_conf_t type_configs[logtype_end_of_list_marker];
160 /* =========================================================================
161 Global function decarations
162 ========================================================================= */
167 /* Setup the level and type of log that will be logged for file loggging */
168 void log_setup(const char *filename, enum loglevels loglevel, enum logtypes logtype);
170 /* Setup the level and type of log that will be logged to syslog. */
171 void syslog_setup(int loglevel, enum logtypes logtype,
172 int display_options, int facility);
174 /* This gets called e.g. from afpd.conf parsing code with a string like: */
175 /* "default log_maxdebug /var/log/afpd.log" */
176 void setuplog(const char *logstr);
178 /* This gets called e.g. from afpd.conf parsing code with a string like: */
179 /* "default dummyname" */
180 void unsetuplog(const char *logstr);
182 /* finish up and close the logs */
183 void log_close(void);
185 /* This function sets up the ProcessName */
186 void set_processname(const char *processname);
188 /* LOG macro func no.1: log the message to file */
189 UAM_MODULE_EXPORT void make_log_entry(enum loglevels loglevel, enum logtypes logtype, const char *file, int line, char *message, ...);
192 * How to write a LOG macro:
193 * http://c-faq.com/cpp/debugmacs.html
195 * We choose the verbose form in favor of the obfuscated ones, its easier
196 * to parse for human beings and facilitates expanding the macro for
197 * inline checks for debug levels.
199 * How to properly enclose multistatement macros:
200 * http://en.wikipedia.org/wiki/C_macro#Multiple_statements
203 #define LOG_MAX log_info
207 #define LOG(log_level, type, ...) \
209 if (log_level <= LOG_MAX) \
210 if (log_level <= type_configs[type].level) \
211 make_log_entry((log_level), (type), __FILE__, __LINE__, __VA_ARGS__); \
214 #else /* ! NO_DEBUG */
216 #define LOG(log_level, type, ...) \
218 if (log_level <= type_configs[type].level) \
219 make_log_entry((log_level), (type), __FILE__, __LINE__, __VA_ARGS__); \
222 #endif /* NO_DEBUG */
224 #endif /* _ATALK_LOGGER_H */