Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

log.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  * log.h - logging functions
00059  *
00060  * Please note that opening and closing of log files are not thread safe.
00061  * Don't do it unless you're in single-thread mode.
00062  */
00063 
00064 #ifndef GWLOG_H
00065 #define GWLOG_H
00066 
00067 /* Symbolic levels for output levels. */
00068 enum output_level {
00069     GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR, GW_PANIC
00070 };
00071 
00072 /* defines if a log-file is exclusive or not */
00073 enum excl_state {
00074     GW_NON_EXCL, GW_EXCL
00075 };
00076 
00077 /* Initialize the log file module */
00078 void log_init(void);
00079 
00080 /* Shutdown the log file module */
00081 void log_shutdown(void);
00082 
00083 /* Print a panicky error message and terminate the program with a failure.
00084  * So, this function is called when there is no other choice than to exit
00085  * immediately, with given reason
00086  */
00087 #define panic   gw_panic
00088 
00089 void gw_panic(int, const char *, ...) PRINTFLIKE(2,3);
00090 
00091 /* Print a normal error message. Used when something which should be
00092  * investigated and possibly fixed, happens. The error might be fatal, too,
00093  * but we have time to put system down peacefully.
00094  */
00095 void error(int, const char *, ...) PRINTFLIKE(2,3);
00096 
00097 /* Print a warning message. 'Warning' is a message that should be told and
00098  * distinguished from normal information (info), but does not necessary 
00099  * require any further investigations. Like 'warning, no sender number set'
00100  */
00101 void warning(int, const char *, ...) PRINTFLIKE(2,3);
00102 
00103 /* Print an informational message. This information should be limited to
00104  * one or two rows per request, if real debugging information is needed,
00105  * use debug
00106  */
00107 void info(int, const char *, ...) PRINTFLIKE(2,3);
00108 
00109 /*
00110  * Print a debug message. Most of the log messages should be of this level 
00111  * when the system is under development. The first argument gives the `place'
00112  * where the function is called from; see function set_debug_places.
00113  */
00114 void debug(const char *, int, const char *, ...) PRINTFLIKE(3,4);
00115 
00116 
00117 /*
00118  * Set the places from which debug messages are actually printed. This
00119  * allows run-time configuration of what is and is not logged when debug
00120  * is called. `places' is a string of tokens, separated by whitespace and/or
00121  * commas, with trailing asterisks (`*') matching anything. For instance,
00122  * if `places' is "wap.wsp.* wap.wtp.* wapbox", then all places that begin 
00123  * with "wap.wsp." or "wap.wtp." (including the dots) are logged, and so 
00124  * is the place called "wapbox". Nothing else is logged at debug level, 
00125  * however. The 'places' string can also have negations, marked with '-' at 
00126  * the start, so that nothing in that place is outputted. So if the string is
00127  * "wap.wsp.* -wap.wap.http", only wap.wsp is logged, but not http-parts on 
00128  * it
00129  */
00130 void log_set_debug_places(const char *places);
00131 
00132 /* Set minimum level for output messages to stderr. Messages with a lower 
00133    level are not printed to standard error, but may be printed to files
00134    (see below). */
00135 void log_set_output_level(enum output_level level);
00136 
00137 /* Set minimum level for output messages to logfiles */
00138 void log_set_log_level(enum output_level level);
00139 
00140 /*
00141  * Set syslog usage. If `ident' is NULL, syslog is not used.
00142  */
00143 void log_set_syslog(const char *ident, int syslog_level);
00144 
00145 /* Start logging to a file as well. The file will get messages at least of
00146    level `level'. There is no need and no way to close the log file;
00147    it will be closed automatically when the program finishes. Failures
00148    when opening to the log file are printed to stderr. 
00149    Where `excl' defines if the log file will be exclusive or not.
00150    Returns the index within the global logfiles[] array where this
00151    log file entry has been added. */
00152 int log_open(char *filename, int level, enum excl_state excl);
00153 
00154 /* Close and re-open all logfiles */
00155 void log_reopen(void);
00156 
00157 /*
00158  * Close all log files.
00159  */
00160 void log_close_all(void);
00161 
00162 /* 
00163  * Register a thread to a specific logfiles[] index and hence 
00164  * to a specific exclusive log file.
00165  */
00166 void log_thread_to(unsigned int idx);
00167 
00168 #endif
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.