1 /* 2 * $Id: errlog.h 191 2007-03-30 23:26:38Z boote $ 3 */ 4 /************************************************************************ 5 * * 6 * Copyright (C) 2002 * 7 * Internet2 * 8 * All Rights Reserved * 9 * * 10 ************************************************************************/ 11 /* 12 * File: errlog.h 13 * 14 * Author: Jeff Boote 15 * Internet2 16 * 17 * Date: Tue Apr 23 14:21:24 2002 18 * 19 * Description: 20 * Generic Error logging API. 21 * 22 * Modified from code writen by John Clyne at UCAR... 23 * 24 * Based on code from UCAR DCS tools. Copyright information 25 * from UCAR follows: 26 * 27 * Copyright 1997 University Corporation for Atmospheric Research, 28 * Scientific Computing Division. All rights reserved. 29 * 30 * 31 * Permission to use, copy, modify and distribute this software 32 * and its documentation for any academic, educational and 33 * scientific research purpose is hereby granted without fee, 34 * provided that the above copyright notice and this permission 35 * notice appear in all copies of this software and its 36 * documentation, and that the software is not sold and/or made 37 * the subject of any commercial activity. Parties interested 38 * in commercial licensing should contact the copyright holder. 39 */ 40 #ifndef _i2_errlog_h_ 41 #define _i2_errlog_h_ 42 43 #include <I2util/util.h> 44 45 #include <stdio.h> 46 #include <stdarg.h> 47 #include <syslog.h> 48 #include <errno.h> 49 50 BEGIN_C_DECLS 51 52 /* 53 * TODO: Verify that this is a portable constant to use for LOG_PERROR... 54 */ 55 #ifndef LOG_PERROR 56 #define LOG_PERROR 0x20 57 #endif 58 59 #define I2NAME (1L << 0) 60 #define I2FILE (1L << 1) 61 #define I2LINE (1L << 2) 62 #define I2DATE (1L << 3) 63 #define I2RTIME (1L << 4) 64 #define I2MSG (1L << 5) 65 #define I2CODE (1L << 6) 66 #define I2LEVEL (1L << 7) 67 #define I2NONL (1L << 8) 68 69 /* basically used to disable syslog messages, but will work for others. */ 70 /* set as "priority" to disable *ALL* syslog messages */ 71 #define I2LOG_NONE 8 72 73 /* Used as "no error" code. */ 74 #define I2EUNKNOWN 0 75 /* 76 * mask is bitwise OR of above bitmasks indicating which of the 77 * remaining fields are valid. 78 * (setting level to a negative number disables logging entirely.) 79 */ 80 struct I2ErrLogEvent{ 81 int mask; 82 const char *name; /* I2NAME */ 83 const char *file; /* I2FILE */ 84 int line; /* I2LINE */ 85 const char *date; /* I2DATE */ 86 int code; /* I2CODE */ 87 int level; /* I2LEVEL - matches Syslog priority */ 88 const char *msg; /* I2MSG */ 89 }; 90 91 typedef void *I2ErrHandle; 92 93 typedef void (*I2ErrLogFuncPtr) ( /* client logging function */ 94 struct I2ErrLogEvent *err_event, 95 void *arg, 96 void **data 97 ); 98 99 typedef I2Boolean (*I2ErrLogResetFuncPtr)( /* reset logging function*/ 100 void *arg, 101 void **data 102 ); 103 104 typedef char *(*I2ErrRetrieveFuncPtr)( /* client fetch func */ 105 void *arg, 106 void **data 107 ); 108 109 110 /* 111 * extern void I2ErrLog(eh,fmt,...); 112 */ 113 #define I2ErrLog I2ErrLocation_(__FILE__, __DATE__, __LINE__); \ 114 I2ErrLogFunction_ 115 /* 116 * extern void I2ErrLogP(eh,err_code,fmt,...); 117 */ 118 #define I2ErrLogP I2ErrLocation_(__FILE__, __DATE__, __LINE__); \ 119 I2ErrLogPFunction_ 120 121 /* 122 * extern void I2ErrLogT(eh,err_level,err_code,fmt,...); 123 */ 124 #define I2ErrLogT I2ErrLocation_(__FILE__,__DATE__,__LINE__); \ 125 I2ErrLogTFunction_ 126 127 128 129 extern I2ErrHandle I2ErrOpen( 130 const char *program_name, 131 I2ErrLogFuncPtr log_func, 132 void *log_func_arg, 133 I2ErrRetrieveFuncPtr retrieve_func, 134 void *retrieve_func_arg 135 ); 136 137 extern void I2ErrSetResetFunc( 138 I2ErrHandle eh, 139 I2ErrLogResetFuncPtr reset_func 140 ); 141 142 /* 143 * If the ErrReset function fails, this will return NULL - and the 144 * ErrHandle will be invalid. 145 */ 146 extern I2ErrHandle I2ErrReset( 147 I2ErrHandle eh 148 ); 149 150 extern void I2ErrClose(I2ErrHandle dpeh); 151 152 extern void I2ErrRep( 153 I2ErrHandle dpeh, 154 FILE *fp 155 ); 156 157 extern char *I2ErrGetMsg( 158 I2ErrHandle dpeh 159 ); 160 161 extern int I2ErrGetCode( 162 I2ErrHandle dpeh 163 ); 164 165 extern void I2ErrLocation_( 166 const char *file, 167 const char *date, 168 int line 169 ); 170 171 /* 172 * Function: I2ErrLogVT 173 * 174 * Description: 175 * 176 * In Args: 177 * (setting level to a negative number disables logging entirely.) 178 * 179 * Out Args: 180 * 181 * Scope: 182 * Returns: 183 * Side Effect: 184 */ 185 extern void 186 I2ErrLogVT( 187 I2ErrHandle dpeh, 188 int level, 189 int code, 190 const char *format, 191 va_list ap 192 ); 193 194 extern void I2ErrLogFunction_( 195 I2ErrHandle dpeh, 196 const char *format, 197 ... 198 ); 199 200 extern void I2ErrLogPFunction_( 201 I2ErrHandle dpeh, 202 int err_code, 203 const char *format, 204 ... 205 ); 206 207 extern void I2ErrLogTFunction_( 208 I2ErrHandle dpeh, 209 int priority, 210 int err_code, 211 const char *format, 212 ... 213 ); 214 215 216 extern int I2ErrList( 217 I2ErrHandle dpeh, 218 unsigned start, 219 unsigned num, 220 const char **err_list 221 ); 222 223 END_C_DECLS 224 225 #include <I2util/errlogimmediate.h> 226 #include <I2util/errlogsyslog.h> 227 228 #endif /* _i2_errlog_h_ */ 229