-
#ifndef _ATALK_LOGGER_H
#define _ATALK_LOGGER_H 1
+/*
+ * logger LOG Macro Usage
+ * ======================
+ *
+ * LOG(<logtype>, <loglevel>, "<string>"[, args]);
+ *
+ *
+ * logger API Setup
+ * ================
+ *
+ * Standard interface:
+ * -------------------
+ *
+ * setuplog(char *confstring)
+ * confstring = "<logtype> <loglevel> [<filename>]"
+ *
+ * Calling without <filename> configures basic logging to syslog. Specifying <filename>
+ * configures extended logging to <filename>.
+ *
+ * You can later disable logging by calling
+ *
+ * unsetuplog(char *confstring)
+ * confstring = "<logtype> [<any_string>]"
+ *
+ * Calling without <any_string> disables syslog logging, calling with <any_string>
+ * disables file logging.
+ *
+ * <logtype>:
+ * you can setup a default with "Default". Any other logtype used in LOG will then
+ * use the default if not setup itself. This is probabyl the only thing you may
+ * want to use.
+ *
+ * Example:
+ * setuplog("default log_debug /var/log/debug.log");
+ * See also libatalk/util/test/logger_test.c
+ *
+ * "Legacy" interface:
+ * -------------------
+ *
+ * Some netatalk daemons (31.3.2009.: e.g. atalkd, papd) may not be converted to
+ * use the new API and might still call
+ *
+ * syslog_setup(int loglevel, enum logtypes logtype, int display_options, int facility);
+ *
+ * directly. These daemons are therefore limited to syslog logging. Also their
+ * loglevel can't be changed at runtime.
+ *
+ *
+ * Note:
+ * dont get confused by log_init(). It only gets called if your app
+ * forgets to setup logging before calling LOG.
+ */
+
+
+#include <limits.h>
+#include <stdio.h>
+
#include <atalk/boolean.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#define MAXLOGSIZE 512
-
enum loglevels {
- log_severe = 0,
- log_error = 10,
- log_warning = 20,
- log_note = 30,
- log_info = 40,
- log_debug = 50
+ log_none,
+ log_severe,
+ log_error,
+ log_warning,
+ log_note,
+ log_info,
+ log_debug,
+ log_debug6,
+ log_debug7,
+ log_debug8,
+ log_debug9,
+ log_maxdebug
};
/* this is the enum specifying all availiable logtypes */
logtype_default,
logtype_core,
logtype_logger,
+ logtype_cnid,
+ logtype_afpd,
+ logtype_atalkd,
+ logtype_papd,
+ logtype_uams,
logtype_end_of_list_marker /* don't put any logtypes after this */
};
-/* these are the string identifiers corresponding to each logtype */
-#define LOGTYPE_STRING_IDENTIFIERS { \
- "Default", \
- "Core", \
- "Logger", \
- \
- "end_of_list_marker"} \
/* Display Option flags. */
/* redefine these so they can don't interfeer with syslog */
/* these can be used in standard logging too */
-#define logoption_pid 0x01 /* log the pid with each message */
-#define logoption_cons 0x02 /* log on the console if errors in sending */
-#define logoption_ndelay 0x08 /* don't delay open */
-#define logoption_perror 0x20 /* log to stderr as well */
-#define logoption_nfile 0x40 /* don't log the file name that called the log */
-#define logoption_nline 0x80 /* don't log the line number from where the log was called */
+#define logoption_nsrcinfo 0x04 /* don't log source info */
+/* the following do not work anymore, they're only provided in order to not
+ * break existing source code */
+#define logoption_pid 0x01 /* log the pid with each message */
+#define logoption_cons 0x02 /* log on the console if error logging */
+#define logoption_ndelay 0x08 /* don't delay open */
+#define logoption_perror 0x20 /* log to stderr as well */
+#define logoption_nfile 0x40 /* ignore the file that called the log */
+#define logoption_nline 0x80 /* ignore the line that called the log*/
/* facility codes */
/* redefine these so they can don't interfeer with syslog */
#define logfacility_mail (2<<3) /* mail system */
#define logfacility_daemon (3<<3) /* system daemons */
#define logfacility_auth (4<<3) /* security/authorization messages */
-#define logfacility_syslog (5<<3) /* messages generated internally by syslogd */
+#define logfacility_syslog (5<<3) /* messages generated by syslogd */
#define logfacility_lpr (6<<3) /* line printer subsystem */
-#define logfacility_authpriv (10<<3) /* security/authorization messages (private) */
+#define logfacility_authpriv (10<<3) /* security/auth messages (private) */
#define logfacility_ftp (11<<3) /* ftp daemon */
-/* Setup the log filename and the loglevel, and the type of log it is. */
-/* setup the internal variables used by the logger (called automatically) */
-void log_init();
-
-bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype, int display_options);
-
-/* Setup the Level and type of log that will be logged to syslog. */
-void syslog_setup(enum loglevels loglevel, enum logtypes logtype, int display_options, int facility);
+/* =========================================================================
+ Global function decarations
+ ========================================================================= */
-/* finish up and close the logs */
-void log_close();
+/* */
+void log_init(void);
-/* This function sets up the ProcessName */
-void set_processname(char *processname);
+/* Setup the level and type of log that will be logged for file loggging */
+void log_setup(const char *filename, enum loglevels loglevel, enum logtypes logtype);
-/* Log a Message */
-void make_log_entry(enum loglevels loglevel, enum logtypes logtype,
- char *message, ...);
+/* Setup the level and type of log that will be logged to syslog. */
+void syslog_setup(int loglevel, enum logtypes logtype,
+ int display_options, int facility);
-#ifndef DISABLE_LOGGER
-typedef void(*make_log_func)
- (enum loglevels loglevel, enum logtypes logtype, char *message, ...);
-make_log_func set_log_location(char *srcfilename, int srclinenumber);
+/* This gets called e.g. from afpd.conf parsing code with a string like: */
+/* "default log_maxdebug /var/log/afpd.log" */
+void setuplog(const char *logstr);
-void LoadProccessNameFromProc();
+/* This gets called e.g. from afpd.conf parsing code with a string like: */
+/* "default dummyname" */
+void unsetuplog(const char *logstr);
-#define LOG set_log_location(__FILE__, __LINE__)
-#else /* DISABLE_LOGGER */
-/* if the logger is disabled the rest is a bit futile */
-#define LOG make_log_entry
-#endif /* DISABLE_LOGGER */
+/* finish up and close the logs */
+void log_close(void);
+/* This function sets up the ProcessName */
+void set_processname(const char *processname);
+
+/*
+ * How to write a LOG macro:
+ * http://c-faq.com/cpp/debugmacs.html
+ *
+ * We choose the verbose form in favor of the obfuscated ones, its easier
+ * to parse for human beings and facilitates expanding the macro for
+ * inline checks for debug levels.
+ *
+ * How to properly enclose multistatement macros:
+ * http://en.wikipedia.org/wiki/C_macro#Multiple_statements
+ */
+
+/* LOG macro func no.1: log the message to file */
+void make_log_entry(enum loglevels loglevel, enum logtypes logtype, const char *file, int line, char *message, ...);
+
+/*
+ Note:
+ any configured file-logging deactivates syslog logging
+ log_level is always a constant with O2 a sane compiler will remove the call to
+ make_log_entry
+ */
+#ifdef NO_DEBUG
+#define LOG_MAX log_info
+#else
+#define LOG_MAX log_maxdebug
#endif
+
+#define LOG(log_level, type, ...) \
+ do { \
+ if (log_level > LOG_MAX) \
+ break; \
+ make_log_entry((log_level), (type), __FILE__, __LINE__, __VA_ARGS__); \
+ } while(0)
+#endif /* _ATALK_LOGGER_H */