]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/log.h
63d0e05ca6c4674fc5a669ecc0bdb3b09b6cdb6e
[OpenSRF.git] / include / opensrf / log.h
1 #ifndef OSRF_LOG_INCLUDED
2 #define OSRF_LOG_INCLUDED
3
4 /**
5         @file log.h
6         @brief Header for logging routines.
7 */
8
9 #include <opensrf/utils.h>
10
11 #include <syslog.h>
12 #include <stdio.h>
13 #include <time.h>
14 #include <errno.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /* log levels */
21 #define OSRF_LOG_ERROR 1
22 #define OSRF_LOG_WARNING 2
23 #define OSRF_LOG_INFO 3
24 #define OSRF_LOG_DEBUG 4
25 #define OSRF_LOG_INTERNAL 5
26 #define OSRF_LOG_ACTIVITY -1
27
28 #define OSRF_LOG_TYPE_FILE 1
29 #define OSRF_LOG_TYPE_SYSLOG 2
30 #define OSRF_LOG_TYPE_STDERR 3
31
32 #define OSRF_LOG_MARK __FILE__, __LINE__
33
34
35 /* Initializes the logger. */
36 void osrfLogInit( int type, const char* appname, int maxlevel );
37
38 /** Sets the systlog facility for the regular logs */
39 void osrfLogSetSyslogFacility( int facility );
40
41 /** Sets the systlog facility for the activity logs */
42 void osrfLogSetSyslogActFacility( int facility );
43
44 /** Reroutes logged messages to standard error; */
45 /** intended for development and debugging */
46 void osrfLogToStderr( void );
47
48 /** Undoes the effects of osrfLogToStderr() */
49 void osrfRestoreLogType( void );
50
51 /** Sets the log file to use if we're logging to a file */
52 void osrfLogSetFile( const char* logfile );
53
54 /* once we know which application we're running, call this method to
55  * set the appname so log lines can include the app name */
56 void osrfLogSetAppname( const char* appname );
57
58 /** Set or Get the global log level.  Any log statements with a higher level
59  * than "level" will not be logged */
60 void osrfLogSetLevel( int loglevel );
61 int osrfLogGetLevel( void );
62
63 /* Log an error message */
64 void osrfLogError( const char* file, int line, const char* msg, ... );
65
66 /* Log a warning message */
67 void osrfLogWarning( const char* file, int line, const char* msg, ... );
68
69 /* log an info message */
70 void osrfLogInfo( const char* file, int line, const char* msg, ... );
71
72 /* Log a debug message */
73 void osrfLogDebug( const char* file, int line, const char* msg, ... );
74
75 /* Log an internal debug message */
76 void osrfLogInternal( const char* file, int line, const char* msg, ... );
77
78 /* Log an activity message */
79 void osrfLogActivity( const char* file, int line, const char* msg, ... );
80
81 void osrfLogCleanup( void );
82
83 void osrfLogClearXid( void );
84 /**
85  * Set the log XID.  This only sets the xid if we are not the origin client 
86  */
87 void osrfLogSetXid(char* xid);
88 /**
89  * Set the log XID regardless of whether we are the origin client
90  */
91 void osrfLogForceXid(char* xid);
92 void osrfLogMkXid( void );
93 void osrfLogSetIsClient(int is);
94 const char* osrfLogGetXid( void );
95
96 /* sets the activity flag */
97 void osrfLogSetActivityEnabled( int enabled );
98
99 /* returns the int representation of the log facility based on the facility name
100  * if the facility name is invalid, LOG_LOCAL0 is returned 
101  */
102 int osrfLogFacilityToInt( const char* facility );
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif