1 #ifndef foodaemonloghfoo 2 #define foodaemonloghfoo 3 4 /*** 5 This file is part of libdaemon. 6 7 Copyright 2003-2008 Lennart Poettering 8 9 libdaemon is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Lesser General Public License as 11 published by the Free Software Foundation, either version 2.1 of the 12 License, or (at your option) any later version. 13 14 libdaemon is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public 20 License along with libdaemon. If not, see 21 <http://www.gnu.org/licenses/>. 22 ***/ 23 24 #include <syslog.h> 25 #include <stdarg.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** \file 32 * 33 * Contains a robust API for logging messages 34 */ 35 36 /** Specifies where to send the log messages to. The global variable daemon_log_use takes values of this type. 37 */ 38 enum daemon_log_flags { 39 DAEMON_LOG_SYSLOG = 1, /**< Log messages are written to syslog */ 40 DAEMON_LOG_STDERR = 2, /**< Log messages are written to STDERR */ 41 DAEMON_LOG_STDOUT = 4, /**< Log messages are written to STDOUT */ 42 DAEMON_LOG_AUTO = 8 /**< If this is set a daemon_fork() will 43 change this to DAEMON_LOG_SYSLOG in 44 the daemon process. */ 45 }; 46 47 /** This variable is used to specify the log target(s) to 48 * use. Defaults to DAEMON_LOG_STDERR|DAEMON_LOG_AUTO */ 49 extern enum daemon_log_flags daemon_log_use; 50 51 /** Specifies the syslog identification, use daemon_ident_from_argv0() 52 * to set this to a sensible value or generate your own. */ 53 extern const char* daemon_log_ident; 54 55 #if defined(__GNUC__) && ! defined(DAEMON_GCC_PRINTF_ATTR) 56 #define DAEMON_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b))) 57 #else 58 /** A macro for making use of GCCs printf compilation warnings */ 59 #define DAEMON_GCC_PRINTF_ATTR(a,b) 60 #endif 61 62 /** Log a message using printf format strings using the specified syslog priority 63 * @param prio The syslog priority (PRIO_xxx constants) 64 * @param t,... The text message to log 65 */ 66 void daemon_log(int prio, const char* t, ...) DAEMON_GCC_PRINTF_ATTR(2,3); 67 68 /** This variable is defined to 1 iff daemon_logv() is supported. 69 * @since 0.11 70 * @see daemon_logv() 71 */ 72 #define DAEMON_LOGV_AVAILABLE 1 73 74 /** Same as daemon_log(), but without variadic arguments 75 * @since 0.11 76 * @see DAEMON_LOGV_AVAILABLE 77 */ 78 void daemon_logv(int prio, const char* t, va_list ap); 79 80 /** Return a sensible syslog identification for daemon_log_ident 81 * generated from argv[0]. This will return a pointer to the file name 82 * of argv[0], i.e. strrchr(argv[0], '\')+1 83 * @param argv0 argv[0] as passed to main() 84 * @return The identification string 85 */ 86 char *daemon_ident_from_argv0(char *argv0); 87 88 /** This variable is defined to 1 iff daemon_set_verbosity() is available. 89 * @since 0.14 90 * @see daemon_set_verbosity() 91 */ 92 #define DAEMON_SET_VERBOSITY_AVAILABLE 1 93 94 /** Setter for the verbosity level of standard output. 95 * 96 * @param verbosity_prio Minimum priority level for messages to output 97 * on standard output/error 98 * 99 * Allows to decide which messages to output on standard output/error 100 * streams. All messages are logged to syslog and this setting does 101 * not influence that. 102 * 103 * The default value is LOG_WARNING. 104 * 105 * @since 0.14 106 * @see DAEMON_SET_VERBOSITY_AVAILABLE 107 */ 108 void daemon_set_verbosity(int verbosity_prio); 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif 115