| 1 | /********************************************************************************** |
| 2 | * log.h |
| 3 | * |
| 4 | * Include file for liblog.a. Coding? Include this and link against liblog.a. |
| 5 | * |
| 6 | * At this time; its a simple list manager but I expect that this will evolve into |
| 7 | * a list manager which; |
| 8 | * |
| 9 | * - allows for messages of different severity and types to be stored |
| 10 | * - allows for actions (such as saving to file or poping) to occur on selected message |
| 11 | * types and severities |
| 12 | * |
| 13 | **********************************************************************************/ |
| 14 | |
| 15 | #ifndef INCLUDED_LOG_H |
| 16 | #define INCLUDED_LOG_H |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <stdio.h> |
| 20 | #include <ctype.h> |
| 21 | |
| 22 | #if defined(HAVE_STDARG_H) |
| 23 | # include <stdarg.h> |
| 24 | # define HAVE_STDARGS |
| 25 | #else |
| 26 | # if defined(HAVE_VARARGS_H) |
| 27 | # include <varargs.h> |
| 28 | # ifdef HAVE_STDARGS |
| 29 | # undef HAVE_STDARGS |
| 30 | # endif |
| 31 | # endif |
| 32 | #endif |
| 33 | |
| 34 | |
| 35 | #include <lst.h> |
| 36 | |
| 37 | /***************************************************************************** |
| 38 | * FUNCTION RETURN CODES |
| 39 | *****************************************************************************/ |
| 40 | #define LOG_ERROR 0 |
| 41 | #define LOG_SUCCESS 1 |
| 42 | #define LOG_NO_DATA 2 |
| 43 | |
| 44 | /***************************************************************************** |
| 45 | * SEVERITY |
| 46 | *****************************************************************************/ |
| 47 | #define LOG_INFO 0 |
| 48 | #define LOG_WARNING 1 |
| 49 | #define LOG_CRITICAL 2 |
| 50 | |
| 51 | /***************************************************************************** |
| 52 | * |
| 53 | *****************************************************************************/ |
| 54 | #define LOG_MSG_MAX 1024 |
| 55 | |
| 56 | /***************************************************************************** |
| 57 | * HANDLES |
| 58 | *****************************************************************************/ |
| 59 | typedef struct tLOGMSG |
| 60 | { |
| 61 | char * pszModuleName; /*!< file where message originated */ |
| 62 | char * pszFunctionName; /*!< function where message originated. */ |
| 63 | int nLine; /*!< File line where message originated. */ |
| 64 | int nSeverity; |
| 65 | int nCode; |
| 66 | char * pszMessage; |
| 67 | |
| 68 | } LOGMSG, *HLOGMSG; |
| 69 | |
| 70 | |
| 71 | typedef struct tLOG |
| 72 | { |
| 73 | HLST hMessages; /* list of messages (we may want to switch to vector) */ |
| 74 | |
| 75 | char *pszProgramName; /* liblog will malloc, copy, and free */ |
| 76 | char *pszLogFile; /* NULL, or filename */ |
| 77 | long nMaxMsgs; /* OLDEST WILL BE DELETED ONCE MAX */ |
| 78 | int bOn; /* turn logging on/off (default=off) */ |
| 79 | |
| 80 | } LOG, *HLOG; |
| 81 | |
| 82 | |
| 83 | /***************************************************************************** |
| 84 | * API |
| 85 | *****************************************************************************/ |
| 86 | |
| 87 | int logOpen( HLOG *phLog, char *pszProgramName, char *pszLogFile, long nMaxMsgs ); |
| 88 | int logClose( HLOG hLog ); |
| 89 | int logClear( HLOG hLog ); |
| 90 | int logPushMsg( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMsg ); |
| 91 | int logPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, ... ); |
| 92 | int logvPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, va_list args ); |
| 93 | int logPeekMsg( HLOG hLog, long nMsg, HLOGMSG *phMsg ); |
| 94 | int logPopMsg( HLOG hLog ); |
| 95 | int logOn( HLOG hLog, int bOn ); |
| 96 | |
| 97 | /***************************************************************************** |
| 98 | * SUPPORTING FUNCS (do not call directly) |
| 99 | *****************************************************************************/ |
| 100 | |
| 101 | /****************************** |
| 102 | * _logFreeMsg |
| 103 | * |
| 104 | * 1. This is called by lstDelete() |
| 105 | ******************************/ |
| 106 | void _logFreeMsg( void *pMsg ); |
| 107 | |
| 108 | #endif |
| 109 | |
| 110 | |
| 111 | |