1 /* ==================================================================== 2 * The Kannel Software License, Version 1.0 3 * 4 * Copyright (c) 2001-2014 Kannel Group 5 * Copyright (c) 1998-2001 WapIT Ltd. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Kannel Group (http://www.kannel.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The names "Kannel" and "Kannel Group" must not be used to 28 * endorse or promote products derived from this software without 29 * prior written permission. For written permission, please 30 * contact org@kannel.org. 31 * 32 * 5. Products derived from this software may not be called "Kannel", 33 * nor may "Kannel" appear in their name, without prior written 34 * permission of the Kannel Group. 35 * 36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 40 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 41 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 42 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 45 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 46 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 * ==================================================================== 48 * 49 * This software consists of voluntary contributions made by many 50 * individuals on behalf of the Kannel Group. For more information on 51 * the Kannel Group, please see <http://www.kannel.org/>. 52 * 53 * Portions of this software are based upon software originally written at 54 * WapIT Ltd., Helsinki, Finland for the Kannel project. 55 */ 56 57 /* 58 * log.h - logging functions 59 * 60 * Please note that opening and closing of log files are not thread safe. 61 * Don't do it unless you're in single-thread mode. 62 */ 63 64 #ifndef GWLOG_H 65 #define GWLOG_H 66 67 /* Symbolic levels for output levels. */ 68 enum output_level { 69 GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR, GW_PANIC, GW_BACKTRACE 70 }; 71 72 /* defines if a log-file is exclusive or not */ 73 enum excl_state { 74 GW_NON_EXCL, GW_EXCL 75 }; 76 77 /* Initialize the log file module */ 78 void log_init(void); 79 80 /* Shutdown the log file module */ 81 void log_shutdown(void); 82 83 /* Print a panicky error message and terminate the program with a failure. 84 * So, this function is called when there is no other choice than to exit 85 * immediately, with given reason 86 */ 87 #define panic gw_panic 88 89 void gw_panic(int, const char *, ...) PRINTFLIKE(2,3); 90 91 /* 92 * Print given stacktrace. If no stackstrace given then stacktrace will be 93 * initialized 94 */ 95 void gw_backtrace(void **, size_t, int); 96 97 /* Print a normal error message. Used when something which should be 98 * investigated and possibly fixed, happens. The error might be fatal, too, 99 * but we have time to put system down peacefully. 100 */ 101 void error(int, const char *, ...) PRINTFLIKE(2,3); 102 103 /* Print a warning message. 'Warning' is a message that should be told and 104 * distinguished from normal information (info), but does not necessary 105 * require any further investigations. Like 'warning, no sender number set' 106 */ 107 void warning(int, const char *, ...) PRINTFLIKE(2,3); 108 109 /* Print an informational message. This information should be limited to 110 * one or two rows per request, if real debugging information is needed, 111 * use debug 112 */ 113 void info(int, const char *, ...) PRINTFLIKE(2,3); 114 115 /* 116 * Print a debug message. Most of the log messages should be of this level 117 * when the system is under development. The first argument gives the `place' 118 * where the function is called from; see function set_debug_places. 119 */ 120 void debug(const char *, int, const char *, ...) PRINTFLIKE(3,4); 121 122 123 /* 124 * Set the places from which debug messages are actually printed. This 125 * allows run-time configuration of what is and is not logged when debug 126 * is called. `places' is a string of tokens, separated by whitespace and/or 127 * commas, with trailing asterisks (`*') matching anything. For instance, 128 * if `places' is "wap.wsp.* wap.wtp.* wapbox", then all places that begin 129 * with "wap.wsp." or "wap.wtp." (including the dots) are logged, and so 130 * is the place called "wapbox". Nothing else is logged at debug level, 131 * however. The 'places' string can also have negations, marked with '-' at 132 * the start, so that nothing in that place is outputted. So if the string is 133 * "wap.wsp.* -wap.wap.http", only wap.wsp is logged, but not http-parts on 134 * it 135 */ 136 void log_set_debug_places(const char *places); 137 138 /* Set minimum level for output messages to stderr. Messages with a lower 139 level are not printed to standard error, but may be printed to files 140 (see below). */ 141 void log_set_output_level(enum output_level level); 142 143 /* Set minimum level for output messages to logfiles */ 144 void log_set_log_level(enum output_level level); 145 146 /* 147 * Set the syslog facility to use. 148 */ 149 void log_set_syslog_facility(char *facility); 150 151 /* 152 * Set syslog usage. If `ident' is NULL, syslog is not used. 153 */ 154 void log_set_syslog(const char *ident, int syslog_level); 155 156 /* Start logging to a file as well. The file will get messages at least of 157 level `level'. There is no need and no way to close the log file; 158 it will be closed automatically when the program finishes. Failures 159 when opening to the log file are printed to stderr. 160 Where `excl' defines if the log file will be exclusive or not. 161 Returns the index within the global logfiles[] array where this 162 log file entry has been added. */ 163 int log_open(char *filename, int level, enum excl_state excl); 164 165 /* Close and re-open all logfiles */ 166 void log_reopen(void); 167 168 /* 169 * Close all log files. 170 */ 171 void log_close_all(void); 172 173 /* 174 * Register a thread to a specific logfiles[] index and hence 175 * to a specific exclusive log file. 176 */ 177 void log_thread_to(unsigned int idx); 178 179 #endif 180