/* Copyright (C) 2008 Andreas Baumann This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef WOLF_LOG_H #define WOLF_LOG_H #include "port/stdbool.h" /* for bool */ #include "port/string.h" /* for strlcpy */ #include "i18n/gettext.h" /* for _ */ /** * @addtogroup wolf_log Logging * @{ */ /** * @file log.h * @brief functions for logging (syslog, eventlog, logfiles, stderr) * @author Andreas Baumann */ #ifdef __cplusplus extern "C" { #endif #if defined HAVE_SYSLOG_H /** * @brief defined if we have a syslogd daemon (Unix usually) */ #define WOLF_LOG_HAVE_SYSLOG #endif #if defined HAVE_EVENTLOG /** * @brief defined if we have an event logger (Windows only) */ #define WOLF_LOG_HAVE_EVENTLOG #endif /** * @brief severity levels. Similarly defined as in syslog.h */ typedef enum { WOLF_LOG_EMERG = 0, /**< system is unusable */ WOLF_LOG_ALERT = 1, /**< action must be taken immediately */ WOLF_LOG_CRIT = 2, /**< critical conditions */ WOLF_LOG_ERR = 3, /**< error conditions */ WOLF_LOG_WARNING = 4, /**< warning conditions */ WOLF_LOG_NOTICE = 5, /**< normal but significant condition */ WOLF_LOG_INFO = 6, /**< informational */ WOLF_LOG_DEBUG = 7, /**< debug-level messages */ WOLF_LOG_DEBUG0 = 7, /**< debug-level, same as WOLF_LOG_DEBUG */ WOLF_LOG_DEBUG1 = 8, /**< debug-level messages */ WOLF_LOG_DEBUG2 = 9, /**< debug-level messages */ WOLF_LOG_DEBUG3 = 10, /**< debug-level messages */ WOLF_LOG_DEBUG4 = 11, /**< debug-level messages */ WOLF_LOG_DEBUG5 = 12 /**< debug-level messages */ } wolf_log_level_t; #if defined HAVE_SYSLOG_H /** * @brief Possible syslog facilities. Not the same on all Unix systems. */ typedef enum { WOLF_LOG_KERN = 0, /**< kernel messages */ WOLF_LOG_USER = 1, /**< random user-level messages */ WOLF_LOG_MAIL = 2, /**< mail system */ WOLF_LOG_DAEMON = 3, /**< system daemons */ WOLF_LOG_AUTH = 4, /**< security/authorization messages */ WOLF_LOG_SYSLOG = 5, /**< messages generated internally by syslogd */ WOLF_LOG_LPR = 6, /**< line printer subsystem */ WOLF_LOG_NEWS = 7, /**< network news subsystem */ WOLF_LOG_UUCP = 8, /**< UUCP subsystem */ WOLF_LOG_CRON = 9, /**< cron/at subsystem */ WOLF_LOG_AUTHPRIV = 10, /**< security/authorization messages (private) */ WOLF_LOG_FTP = 11, /**< ftp daemon */ WOLF_LOG_NTP = 12, /**< ntp daemon (FreeBSD only) */ WOLF_LOG_SECURITY = 13, /**< security subsystems (firewalling, etc., FreeBSD only) */ WOLF_LOG_CONSOLE = 14, /**< /dev/console output (FreeBSD only) */ WOLF_LOG_AUDIT = 15, /**< audit subsystem (Solaris 10 only) */ WOLF_LOG_LOCAL0 = 16, /**< local facility 0 */ WOLF_LOG_LOCAL1 = 17, /**< local facility 1 */ WOLF_LOG_LOCAL2 = 18, /**< local facility 2 */ WOLF_LOG_LOCAL3 = 19, /**< local facility 3 */ WOLF_LOG_LOCAL4 = 20, /**< local facility 4 */ WOLF_LOG_LOCAL5 = 21, /**< local facility 5 */ WOLF_LOG_LOCAL6 = 22, /**< local facility 6 */ WOLF_LOG_LOCAL7 = 23 /**< local facility 7 */ } wolf_log_syslog_facility_t; #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_SYSLOG_H /** * @brief Options for opening the system logger, as defined by the Open Group. * * Note: LOG_ODELAY, LOG_NDELAY, LOG_NOWAIT are more or less deprecated, * also LOG_PERROR is not POSIX and can be replaced with a stderr logger. */ typedef enum { WOLF_LOG_SYSLOG_PID = 1, /**< log the process ID with each message */ WOLF_LOG_SYSLOG_CONS = 2 /**< log to the system console on error */ } wolf_log_syslog_option_t; #endif /* defined HAVE_SYSLOG_H */ /** * @brief The default options to pass to the system logger. */ #if defined HAVE_SYSLOG_H #define WOLF_LOG_SYSLOG_DEFAULT_OPTIONS WOLF_LOG_SYSLOG_PID | WOLF_LOG_SYSLOG_CONS #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_SYSLOG_H /** * Convert a wolf_log_syslog_facility_t to its string representation. * * @param facility a wolf_log_syslog_facility_t * @return a string constant like "DAEMON" */ const char *wolf_log_syslog_facility_to_str( wolf_log_syslog_facility_t facility ); #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_SYSLOG_H /** * Convert a name of a syslog facility like "DAEMON" to the corresponding * wolf_log_syslog_facility_t * * @param facility a string like "DAEMON" * @return the matching wolf_log_syslog_facility_t or -1 if the * passed facility is not known */ wolf_log_syslog_facility_t wolf_log_str_to_syslog_facility( const char *facility ); #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_SYSLOG_H /** * Returns if the current platform knows about the given syslog facility. * * @param facility a wolf_log_syslog_facility_t * @return true if the facility exists, false if not */ bool wolf_log_platform_has_syslog_facility( wolf_log_syslog_facility_t facility ); #endif /* defined HAVE_SYSLOG_H */ /** * Convert a wolf_log_level_t to its string representation. * * @param level a wolf_log_level_t * @return a string constant like "NOTICE" */ const char *wolf_log_level_to_str( wolf_log_level_t level ); /** * Convert a name of a level like "NOTICE" to the corresponding * wolf_log_level_t * * @param level a string like "NOTICE" * @return the matching wolf_log_level_t or -1 if the * passed level is not known */ wolf_log_level_t wolf_log_str_to_level( const char *level ); /** * Open a channel for logging to a file. * * @param filename name of the logfile to log to * @param level one out of wolf_log_level_t, the minimal level which * should be logged into the logfile */ void wolf_log_openlogtofile( const char *filename, wolf_log_level_t level ); #if defined HAVE_SYSLOG_H /** * Open a channel to the Unix system logger. * * @param ident identifies the programm using the logger * @param facility one out of wolf_log_syslog_facility_t e. g. * wolf_log_facility_DAEMON * @param level one out of wolf_log_level_t, the minimal level which * should be logged into syslog * @param options a mask of options of type wolf_log_syslog_option_t, * (default is WOLF_LOG_SYSLOG_DEFAULT_OPTIONS) */ void wolf_log_openlogtosyslog( const char *ident, wolf_log_syslog_facility_t facility, wolf_log_level_t level, int options ); #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_EVENTLOG /** * Open a channel to the Windows event logger. * * @param server name of the server to log to, NULL if local computer * @param log name of the log, usually this should be 'Application' * @param source name of the event log source * @param path_to_dll path to the message/category DLL for the localization * of the categories and messages to log. the string should * be expandable, i.e. about hard-coded drives and paths, * e. g. "%SystemRoot%\\System32\\myapp.dll" * @param nof_cats number of categories in the messages/category DLL * @param level one out of wolf_log_level_t, the minimal level which * should be logged into the event log * */ void wolf_log_openlogtoeventlog( const char *server, const char *log, const char *source, const char *path_to_dll, int nof_cats, wolf_log_level_t level ); #endif /* defined HAVE_EVENTLOG */ /** * Open a channel for logging to stderr. * * @param level one out of wolf_log_level_t, the minimal level which * should be logged into standard error */ void wolf_log_openlogtostderr( wolf_log_level_t level ); /** * Close logging to a logfile. */ void wolf_log_closelogtofile( void ); #if defined HAVE_SYSLOG_H /** * Close logging to the Unix system logger. */ void wolf_log_closelogtosyslog( void ); #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_EVENTLOG /** * Close logging to the Windows event logger. * */ void wolf_log_closelogtoeventlog( void ); #endif /* defined HAVE_EVENTLOG */ /** * Close logging to stderr. */ void wolf_log_closelogtostderr( void ); /** * Reopen logging to a logfile. */ void wolf_log_reopenlogtofile( void ); #if defined HAVE_SYSLOG_H /** * Reopen logging to the Unix system logger. */ void wolf_log_reopenlogtosyslog( void ); #endif /* defined HAVE_SYSLOG_H */ #if defined HAVE_EVENTLOG /** * Reopen logging to the Windows event logger. */ void wolf_log_reopenlogtoeventlog( void ); #endif /* defined HAVE_EVENTLOG */ /** * Write a formatted log message to the logger. * * @param level one of wolf_log_level_t * @param category_id a category as defined in messages.h * @param message_id a message id as defined in messages.h * @param format snprintf like format string, * the rest of the parameters given * as defined in the format string */ void wolf_log( wolf_log_level_t level, int category_id, int message_id, const char *format, ... ); #ifdef __cplusplus } #endif /** @} */ /* @addtogroup wolf_log */ #endif /* ifndef WOLF_LOG_H */