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