File: log.h

package info (click to toggle)
unixodbc 2.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,524 kB
  • ctags: 7,656
  • sloc: ansic: 89,405; sh: 15,975; makefile: 1,574; yacc: 969; sql: 1
file content (110 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**********************************************************************************
 * log.h
 *
 * Include file for liblog.a. Coding? Include this and link against liblog.a.
 *
 * At this time; its a simple list manager but I expect that this will evolve into
 * a list manager which;
 *
 * - allows for messages of different severity and types to be stored
 * - allows for actions (such as saving to file or poping) to occur on selected message
 *   types and severities
 *
 **********************************************************************************/

#ifndef INCLUDED_LOG_H
#define INCLUDED_LOG_H

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#if defined(HAVE_STDARG_H)
# include <stdarg.h>
# define HAVE_STDARGS
#else
# if defined(HAVE_VARARGS_H)
#  include <varargs.h>
#  ifdef HAVE_STDARGS
#   undef HAVE_STDARGS
#  endif
# endif
#endif


#include <lst.h>

/*****************************************************************************
 * FUNCTION RETURN CODES
 *****************************************************************************/
#define     LOG_ERROR               0
#define     LOG_SUCCESS             1
#define		LOG_NO_DATA				2

/*****************************************************************************
 * SEVERITY
 *****************************************************************************/
#define		LOG_INFO				0
#define		LOG_WARNING				1
#define		LOG_CRITICAL			2

/*****************************************************************************
 *
 *****************************************************************************/
#define		LOG_MSG_MAX				1024

/*****************************************************************************
 * HANDLES
 *****************************************************************************/
typedef struct	tLOGMSG
{
	char *  pszModuleName;      /*!< file where message originated                                      */
	char *  pszFunctionName;    /*!< function where message originated.                                 */
	int     nLine;              /*!< File line where message originated.                                */
	int     nSeverity;
	int     nCode;
	char *  pszMessage;

} LOGMSG, *HLOGMSG;


typedef struct	tLOG
{
	HLST		hMessages;								/* list of messages	(we may want to switch to vector)   */

	char		*pszProgramName;						/* liblog will malloc, copy, and free	*/
	char		*pszLogFile;							/* NULL, or filename					*/
	long		nMaxMsgs;								/* OLDEST WILL BE DELETED ONCE MAX		*/
	int			bOn;									/* turn logging on/off (default=off)	*/

} LOG, *HLOG;


/*****************************************************************************
 * API
 *****************************************************************************/

int logOpen( HLOG *phLog, char *pszProgramName, char *pszLogFile, long nMaxMsgs );
int logClose( HLOG hLog );
int logClear( HLOG hLog );
int logPushMsg( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMsg );
int logPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, ... );
int logvPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, va_list args );
int logPeekMsg( HLOG hLog, long nMsg, HLOGMSG *phMsg );
int logPopMsg( HLOG hLog );
int logOn( HLOG hLog, int bOn );

/*****************************************************************************
 * SUPPORTING FUNCS (do not call directly)
 *****************************************************************************/

/******************************
 * _logFreeMsg
 *
 * 1. This is called by lstDelete()
 ******************************/
void _logFreeMsg( void *pMsg );

#endif