summaryrefslogtreecommitdiffstats
path: root/libcsoap/soap-logging.h
blob: 0493a16fde9cf4780c0f70c7951f75f76900a324 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/******************************************************************
 *  $Id: soap-logging.h,v 1.2 2007/11/04 06:57:32 m0gg Exp $
 * 
 * CSOAP Project:  A http client/server library in C
 * Copyright (C) 2003-2006  Ferhat Ayaz
 * Copyright (C) 2007       Heiko Ronsdorf
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * 
 * Email: hero@persua.de
 ******************************************************************/
#ifndef __soap_logging_h
#define __soap_logging_h

/** @file soap-logging.h Logging definitions and prototypes
 *
 * @defgroup CSOAP_LOGGING Logging interface
 * @ingroup CSOAP
 */
/**@{*/

/** @defgroup CSOAP_CDMLINE_LOGGING Commandline flags
 * @ingroup CSOAP_CMDLINE
 */
/**@{*/
#define CSOAP_ARG_LOGFILE	"-CSOAPlog"
#define CSOAP_ARG_LOGLEVEL	"-CSOAPloglevel"
/**@}*/

/** Loglevel definition */
typedef enum soap_loglevel
{
  SOAP_LOG_OFF,     /**< Logging completely turned off (use at your own
		         risk). */
  SOAP_LOG_VERBOSE, /**< Debugging messages thath may overlfow the
		         log */
  SOAP_LOG_DEBUG,   /**< Messages that contain information normallu of
		         use only when debugging the library. */
  SOAP_LOG_INFO,    /**< Infmormational messages */
  SOAP_LOG_WARN,    /**< Warning messages. */
  SOAP_LOG_ERROR,   /**< A condition that should be corrected
		         immediately, such as a broken network
			 connection. */
  SOAP_LOG_FATAL    /**< A panic condition. */
} soap_loglevel_t;

#define SOAP_LOG_LEVEL_OFF_STRING     "OFF"
#define SOAP_LOG_LEVEL_VERBOSE_STRING "VERBOSE"
#define SOAP_LOG_LEVEL_DEBUG_STRING   "DEBUG"
#define SOAP_LOG_LEVEL_INFO_STRING    "INFO"
#define SOAP_LOG_LEVEL_WARN_STRING    "WARN"
#define SOAP_LOG_LEVEL_ERROR_STRING   "ERROR"
#define SOAP_LOG_LEVEL_FATAL_STRING   "FATAL"
#define SOAP_LOG_LEVEL_UNKNOWN_STRING "UNKNWON"

#ifdef __cplusplus
extern "C" {
#endif

/** Set the loglevel.
 *
 * @param level The new loglevel.
 *
 * @return The old loglevel.
 */
extern soap_loglevel_t soap_set_loglevel(soap_loglevel_t loglevel);

/** Get the loglevel.
 *
 * @return The current loglevel.
 */
extern soap_loglevel_t soap_get_loglevel(void);

/** Set the logfile.
 *
 * @param filename The filename of the logfile.
 */
extern void soap_set_logfile(const char *filename);

/** Get the filename of the logfile.
 *
 * @return Pointer to the filename or null otherwise.
 */
extern char *soap_get_logfile(void);

#define SOAP_LOG_DISABLED   0x00 /**< Logging disabled */
#define SOAP_LOG_FOREGROUND 0x01 /**< Logging to stdout enabled */
#define SOAP_LOG_SYSLOG     0x02 /**< Syslog logging enabled */

/** This function sets the type of logging.
 *
 * @return The old logtype.
 *
 * @see - SOAP_LOG_DISABLED
 *      - SOAP_LOG_FOREGROUND
 *      - SOAP_LOG_SYSLOG
 */
extern int soap_log_set_logtype(int type);

#ifdef WIN32
#if defined(_MSC_VER) && _MSC_VER <= 1200
extern char *VisualC_funcname(const char *file, int line);     /* not thread safe! */
#define __FUNCTION__  VisualC_funcname(__FILE__, __LINE__)
#endif
#endif

#ifdef __cplusplus
}
#endif

#define log_verbose(fmt, ...) _nanohttp_log_printf(SOAP_LOG_VERBOSE, \
                              SOAP_LOG_LEVEL_VERBOSE_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

#define log_debug(fmt, ...)   _nanohttp_log_printf(SOAP_LOG_DEBUG, \
                              SOAP_LOG_LEVEL_DEBUG_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

#define log_info(fmt, ...)    _nanohttp_log_printf(SOAP_LOG_INFO, \
                              SOAP_LOG_LEVEL_INFO_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

#define log_warn(fmt, ...)    _nanohttp_log_printf(SOAP_LOG_WARN, \
                              SOAP_LOG_LEVEL_WARN_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

#define log_error(fmt, ...)   _nanohttp_log_printf(SOAP_LOG_ERROR, \
                              SOAP_LOG_LEVEL_ERROR_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

#define log_fatal(fmt, ...)   _nanohttp_log_printf(SOAP_LOG_FATAL, \
                              SOAP_LOG_LEVEL_FATAL_STRING " %s: " fmt "\n", \
                              __FUNCTION__, ## __VA_ARGS__)

/**@}*/

#endif