1 /*----------------------------------------------------------------------------
2 Name: I_Log.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 -----------------------------------------------------------------------------*/
6
7 #ifndef _ORG_XMLBLASTER_UTIL_I_LOG_H
8 #define _ORG_XMLBLASTER_UTIL_I_LOG_H
9
10 #include <util/xmlBlasterDef.h>
11 #include <cstdlib> // exit()
12 #include <string>
13 #include <iostream>
14
15 /**
16 * Interface for logging.
17 * <p />
18 * This allows to customize which logging library you want to use.
19 * The six logging levels used by Log are (in order):
20 *
21 * <p> The six logging levels used by <code>Log</code> are (in order):
22 * <ol>
23 * <li>trace (the least serious)</li>
24 * <li>call (on method entry)</li>
25 * <li>info</li>
26 * <li>warn</li>
27 * <li>error</li>
28 * <li>panic (the most serious, does an exit)</li>
29 * </ol>
30 * The mapping of these log levels to the concepts used by the underlying
31 * logging system is implementation dependent.
32 * The implemention should ensure, though, that this ordering behaves
33 * as expected.</p>
34 *
35 * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>
36 */
37 namespace org { namespace xmlBlaster { namespace util {
38
39 class Dll_Export I_Log {
40
41 protected:
42 /** For better performance */
43 bool call_;
44 bool time_;
45 bool trace_;
46 bool dump_;
47 bool info_;
48
49 public:
50 I_Log() : call_(false), time_(false), trace_(false), dump_(false), info_(true) {}
51 virtual ~I_Log() {}
52
53 /** For better performance try: if (log.call()) log.call("Me","bla"); */
54 inline bool call() const { return call_; }
55 inline bool time() const { return time_; }
56 inline bool trace() const { return trace_; }
57 inline bool dump() const { return dump_; }
58
59 /**
60 * Use this exit for errors
61 * @deprecated
62 */
63 virtual void panic(const std::string &instance, const std::string &text) { error(instance, text); ::exit(1); }
64
65
66 /**
67 * Exit without errors
68 * @deprecated
69 */
70 virtual void exit(const std::string &instance, const std::string &text) { error(instance, text); ::exit(0); }
71
72
73 /**
74 * Use this for normal logging output
75 */
76 virtual void info(const std::string &instance, const std::string &text)= 0;
77
78
79 /**
80 * Use this for logging output where the xmlBlaster administrator shall
81 * be informed<br /> for example a login denied event
82 */
83 virtual void warn(const std::string &instance, const std::string &text)= 0;
84
85
86 /**
87 * Use this for internal xmlBlaster errors reporting
88 */
89 virtual void error(const std::string &instance, const std::string &text)= 0;
90
91
92 /*
93 * Log without time/date/instance (ignoring the header is not supported with all logging frameworks)
94 * @param text the std::string to log
95 * @deprecated
96 */
97 virtual void plain(const std::string &instance, const std::string &text) { info(instance, text); }
98
99
100 /*
101 * Log without time/date
102 * @deprecated
103 */
104 virtual void dump(const std::string &instance, const std::string &text) { trace(instance, text); }
105
106
107 /**
108 * Tracing execution
109 */
110 virtual void trace(const std::string &instance, const std::string &text)= 0;
111
112
113 /**
114 * Tracing when entering methods
115 */
116 virtual void call(const std::string &instance, const std::string &text)= 0;
117
118
119 /**
120 * Output of performance measurements (elapsed milliseconds)
121 * @deprecated
122 */
123 virtual void time(const std::string &instance, const std::string &text) { trace(instance, text); }
124
125 /**
126 * My current log level setting in human readable notation.
127 * @return for example "ERROR|WARN|TRACE"
128 */
129 virtual std::string getLogLevelStr() const { return ""; }
130
131 virtual std::string usage() const { return "No logging usage available, please check the logging documentation"; }
132 }; // end of class I_Log
133
134
135
136 }}} // end of namespace util
137
138 #endif // _ORG_XMLBLASTER_UTIL_I_LOG_H
syntax highlighted by Code2HTML, v. 0.9.1