Main Page | Class List | File List | Class Members | File Members | Related Pages

log.h

Go to the documentation of this file.
00001 /* 00002 * $Id: log.h,v 1.28 2003/10/16 18:50:54 jasta Exp $ 00003 * 00004 * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net) 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the 00008 * Free Software Foundation; either version 2, or (at your option) any 00009 * later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * General Public License for more details. 00015 */ 00016 00017 #ifndef __LOG_H 00018 #define __LOG_H 00019 00020 /*****************************************************************************/ 00021 00032 /*****************************************************************************/ 00033 00034 #ifdef HAVE_SYSLOG_H 00035 # include <syslog.h> 00036 #endif 00037 00038 #ifndef LOG_PERROR 00039 # define LOG_PERROR 0x20 00040 #endif 00041 00042 #ifndef LOG_PFX 00043 # define LOG_PFX NULL 00044 #endif 00045 00046 #ifndef LOG_USER 00047 # define LOG_USER (1 << 31) 00048 #endif 00049 00050 #ifndef LOG_EMERG 00051 # define LOG_EMERG 0 /* system is unusable */ 00052 #endif 00053 00054 #ifndef LOG_ALERT 00055 # define LOG_ALERT 1 /* action must be taken immediately */ 00056 #endif 00057 00058 #ifndef LOG_CRIT 00059 # define LOG_CRIT 2 /* critical conditions */ 00060 #endif 00061 00062 #ifndef LOG_ERR 00063 # define LOG_ERR 3 /* error conditions */ 00064 #endif 00065 00066 #ifndef LOG_WARNING 00067 # define LOG_WARNING 4 /* warning conditions */ 00068 #endif 00069 00070 #ifndef LOG_NOTICE 00071 # define LOG_NOTICE 5 /* normal but significant condition */ 00072 #endif 00073 00074 #ifndef LOG_INFO 00075 # define LOG_INFO 6 /* informational */ 00076 #endif 00077 00078 #ifndef LOG_DEBUG 00079 # define LOG_DEBUG 7 /* debug-level messages */ 00080 #endif 00081 00082 /*****************************************************************************/ 00083 00084 typedef enum 00085 { 00086 GLOG_NONE = 0x00, /* turn logging off */ 00087 GLOG_STDERR = 0x01, /* log to stderr, the default */ 00088 GLOG_STDOUT = 0x02, /* log to stdout */ 00089 GLOG_SYSLOG = 0x04, /* log to syslog (*nix) or Event Log (Win32) */ 00090 GLOG_FILE = 0x08, /* log to the specified file */ 00091 GLOG_DEBUGGER = 0x10 /* log to debugger, if running within debugger */ 00092 } LogOptions; 00093 00094 /*****************************************************************************/ 00095 00096 #define GIFT_INFO(args) (log_info args) 00097 #define GIFT_WARN(args) (log_warn args) 00098 #define GIFT_ERROR(args) (log_error args) 00099 #define GIFT_FATAL(args) (log_fatal args), exit(0) 00100 #define GIFT_ERRNO() (platform_errno()) 00101 #define GIFT_STRERROR() (platform_error()) 00102 #define GIFT_NETERROR() (platform_net_error()) 00103 00104 #ifdef LIBGIFT_DEBUG 00105 00106 # define GIFT_DBG(args) \ 00107 (log_debug args) 00108 # define GIFT_TRACE(args) \ 00109 (log_trace_pfx (LOG_PFX, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL), \ 00110 log_trace args) 00111 # define GIFT_TRACEFN \ 00112 GIFT_TRACE (("entered")) 00113 # define GIFT_TRACEMEM(ptr, len) \ 00114 (log_dump_memory ((void *)(ptr), (unsigned long)(len))) 00115 00116 # define GLOG_DEBUG GLOG_DEBUGGER 00117 00118 #else /* !LIBGIFT_DEBUG */ 00119 00120 # define GIFT_DBG(args) 00121 # define GIFT_TRACE(args) 00122 # define GIFT_TRACEFN 00123 # define GIFT_TRACEMEM(ptr, len) 00124 # define GLOG_DEBUG 00125 00126 #endif /* LIBGIFT_DEBUG */ 00127 00128 /*****************************************************************************/ 00129 00130 #ifdef DEBUG_STDERR 00131 # define GLOG_DEFAULT GLOG_FILE | GLOG_STDERR 00132 #else 00133 # define GLOG_DEFAULT GLOG_FILE 00134 #endif 00135 00136 #if defined (__GNUC__) && 0 00137 # define GIFT_FMTATTR(f,v) __attribute__ ((__format__ (__printf__, f, v))) 00138 #else 00139 # define GIFT_FMTATTR(f,v) 00140 #endif /* __GNUC__ */ 00141 00142 /*****************************************************************************/ 00143 00144 EXTERN_C_BEGIN 00145 00146 /*****************************************************************************/ 00147 00160 LIBGIFT_EXPORT 00161 int log_init (LogOptions options, char *ident, int syslog_option, 00162 int facility, char *log_file); 00163 00167 LIBGIFT_EXPORT 00168 void log_cleanup (); 00169 00174 LIBGIFT_EXPORT 00175 void log_print (int priority, char *msg); 00176 00177 /* 00178 * Usage: 00179 * GIFT_WARN (("cant open %s: %s", file, platform_error())); 00180 * or 00181 * GIFT_WARN (("cant open %s: %s", file, GIFT_STRERROR())); 00182 */ 00183 LIBGIFT_EXPORT 00184 void log_info (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00185 LIBGIFT_EXPORT 00186 void log_warn (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00187 LIBGIFT_EXPORT 00188 void log_error (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00189 LIBGIFT_EXPORT 00190 void log_fatal (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00191 00192 #ifdef LIBGIFT_DEBUG 00193 00194 LIBGIFT_EXPORT 00195 void log_debug (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00196 LIBGIFT_EXPORT 00197 void log_trace_pfx (char *pfx, char *file, int line, char *func, char *extra); 00198 LIBGIFT_EXPORT 00199 void log_trace (const char *fmt, ...) GIFT_FMTATTR (1, 2); 00200 00210 LIBGIFT_EXPORT 00211 void log_dump_memory (void *ptr, unsigned int len); 00212 00213 #endif /* LIBGIFT_DEBUG */ 00214 00215 /*****************************************************************************/ 00216 00217 EXTERN_C_END 00218 00219 /*****************************************************************************/ 00220 00221 #endif /* __LOG_H */

Generated on Sun Aug 22 08:07:10 2004 by doxygen 1.3.7