diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/logger.h | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/logger.h')
-rw-r--r-- | src/stable/logger.h | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/src/stable/logger.h b/src/stable/logger.h index 198ffa2..bcc5a83 100644 --- a/src/stable/logger.h +++ b/src/stable/logger.h | |||
@@ -13,82 +13,82 @@ | |||
13 | 13 | ||
14 | namespace Bu | 14 | namespace Bu |
15 | { | 15 | { |
16 | /** | 16 | /** |
17 | * Simple logging facility. All output goes straight to stdout, unlike the | 17 | * Simple logging facility. All output goes straight to stdout, unlike the |
18 | * old multi-log system. Generally we expect any program complex enough to | 18 | * old multi-log system. Generally we expect any program complex enough to |
19 | * want to use this will have other facilities for processing the logging | 19 | * want to use this will have other facilities for processing the logging |
20 | * output, but if we need it we can add other output methods. | 20 | * output, but if we need it we can add other output methods. |
21 | * | 21 | * |
22 | * Currently implemented as a singleton to avoid clutter with globals, you | 22 | * Currently implemented as a singleton to avoid clutter with globals, you |
23 | * generally never want to use the logging system directly, it's annoying. | 23 | * generally never want to use the logging system directly, it's annoying. |
24 | * Instead use the handy macros lineLog, setLogMask, setLogFormat, and | 24 | * Instead use the handy macros lineLog, setLogMask, setLogFormat, and |
25 | * setLogLevel. They do all the real work for you. | 25 | * setLogLevel. They do all the real work for you. |
26 | * | 26 | * |
27 | * In the log format, you can specify extra information that will be written | 27 | * In the log format, you can specify extra information that will be written |
28 | * to the log with every message, and extras in printf style. Use %X flags | 28 | * to the log with every message, and extras in printf style. Use %X flags |
29 | * where X is one of the following: | 29 | * where X is one of the following: |
30 | * - L - Logging level of the log message (not the current mask) | 30 | * - L - Logging level of the log message (not the current mask) |
31 | * - y - Full year | 31 | * - y - Full year |
32 | * - m - Month | 32 | * - m - Month |
33 | * - d - Day of month | 33 | * - d - Day of month |
34 | * - h - Hour (24-hour format) | 34 | * - h - Hour (24-hour format) |
35 | * - M - Minutes | 35 | * - M - Minutes |
36 | * - s - Seconds | 36 | * - s - Seconds |
37 | * - f - Source file | 37 | * - f - Source file |
38 | * - l - Line number | 38 | * - l - Line number |
39 | * - F - function name | 39 | * - F - function name |
40 | * - t - Text of message (usually important) | 40 | * - t - Text of message (usually important) |
41 | * | 41 | * |
42 | * You can include anything extra that you would like, a newline will always | 42 | * You can include anything extra that you would like, a newline will always |
43 | * be added automatically, so no need to worry about that. You can also | 43 | * be added automatically, so no need to worry about that. You can also |
44 | * include any extra printf style formatting that you would like, for | 44 | * include any extra printf style formatting that you would like, for |
45 | * example: "%h:%02M:%02s" for the time 4:02:09 instead of 4:2:9. | 45 | * example: "%h:%02M:%02s" for the time 4:02:09 instead of 4:2:9. |
46 | * | 46 | * |
47 | * It's generally handy to create an enum of values you use as levels during | 47 | * It's generally handy to create an enum of values you use as levels during |
48 | * program execution (such as error, warning, info, debug, etc). These | 48 | * program execution (such as error, warning, info, debug, etc). These |
49 | * levels should be treated as bitflags, and the most desirable messages, | 49 | * levels should be treated as bitflags, and the most desirable messages, |
50 | * i.e. serious errors and the like should be low order (0x01), and the much | 50 | * i.e. serious errors and the like should be low order (0x01), and the much |
51 | * less desirable messages, like debugging info, should be higher order | 51 | * less desirable messages, like debugging info, should be higher order |
52 | * (0xF0). During operation you can then set either an explicit mask, | 52 | * (0xF0). During operation you can then set either an explicit mask, |
53 | * selecting just the levels that you would like to see printed, or set the | 53 | * selecting just the levels that you would like to see printed, or set the |
54 | * mask using the setLevel helper function, which simulates verbosity | 54 | * mask using the setLevel helper function, which simulates verbosity |
55 | * levels, enabling every flag lower order than the highest order set bit | 55 | * levels, enabling every flag lower order than the highest order set bit |
56 | * passed. I.E. if you had the following enumerated levels: | 56 | * passed. I.E. if you had the following enumerated levels: |
57 | * | 57 | * |
58 | *@code | 58 | *@code |
59 | enum { | 59 | enum { |
60 | logError = 0x01, | 60 | logError = 0x01, |
61 | logWarning = 0x02, | 61 | logWarning = 0x02, |
62 | logInfo = 0x04, | 62 | logInfo = 0x04, |
63 | logDebug = 0x08 | 63 | logDebug = 0x08 |
64 | }; | 64 | }; |
65 | @endcode | 65 | @endcode |
66 | * And you set the mask with setMask( logInfo ) the only messages you would | 66 | * And you set the mask with setMask( logInfo ) the only messages you would |
67 | * see are the ones catagorized logInfo. However, if you used | 67 | * see are the ones catagorized logInfo. However, if you used |
68 | * setLevel( logInfo ) then you would see logInfo, logWarning, and logError | 68 | * setLevel( logInfo ) then you would see logInfo, logWarning, and logError |
69 | * type messages, since they are lower order. | 69 | * type messages, since they are lower order. |
70 | */ | 70 | */ |
71 | class Logger : public Bu::Singleton<Bu::Logger> | 71 | class Logger : public Bu::Singleton<Bu::Logger> |
72 | { | 72 | { |
73 | friend class Bu::Singleton<Bu::Logger>; | 73 | friend class Bu::Singleton<Bu::Logger>; |
74 | private: | 74 | private: |
75 | Logger(); | 75 | Logger(); |
76 | virtual ~Logger(); | 76 | virtual ~Logger(); |
77 | 77 | ||
78 | public: | 78 | public: |
79 | void log( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const char *sFormat, ...); | 79 | void log( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const char *sFormat, ...); |
80 | 80 | ||
81 | void setFormat( const Bu::String &str ); | 81 | void setFormat( const Bu::String &str ); |
82 | void setMask( uint32_t n ); | 82 | void setMask( uint32_t n ); |
83 | void setLevel( uint32_t n ); | 83 | void setLevel( uint32_t n ); |
84 | uint32_t getMask(); | 84 | uint32_t getMask(); |
85 | 85 | ||
86 | void hexDump( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const void *pData, long nDataLen, const char *lpName ); | 86 | void hexDump( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const void *pData, long nDataLen, const char *lpName ); |
87 | 87 | ||
88 | private: | 88 | private: |
89 | Bu::String sLogFormat; | 89 | Bu::String sLogFormat; |
90 | uint32_t nLevelMask; | 90 | uint32_t nLevelMask; |
91 | }; | 91 | }; |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
@@ -97,29 +97,29 @@ namespace Bu | |||
97 | * file, line number, and function. | 97 | * file, line number, and function. |
98 | */ | 98 | */ |
99 | #define lineLog( nLevel, sFrmt, ...) \ | 99 | #define lineLog( nLevel, sFrmt, ...) \ |
100 | Bu::Logger::getInstance().log( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, sFrmt, ##__VA_ARGS__ ) | 100 | Bu::Logger::getInstance().log( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, sFrmt, ##__VA_ARGS__ ) |
101 | 101 | ||
102 | #define logHexDump( nLevel, pData, iSize, sName ) \ | 102 | #define logHexDump( nLevel, pData, iSize, sName ) \ |
103 | Bu::Logger::getInstance().hexDump( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, pData, iSize, sName ) | 103 | Bu::Logger::getInstance().hexDump( nLevel, __FILE__, __PRETTY_FUNCTION__, __LINE__, pData, iSize, sName ) |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * Set the Bu::Logger logging mask directly. See Bu::Logger::setMask for | 106 | * Set the Bu::Logger logging mask directly. See Bu::Logger::setMask for |
107 | * details. | 107 | * details. |
108 | */ | 108 | */ |
109 | #define setLogMask( nLevel ) \ | 109 | #define setLogMask( nLevel ) \ |
110 | Bu::Logger::getInstance().setMask( nLevel ) | 110 | Bu::Logger::getInstance().setMask( nLevel ) |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Set the Bu::Logger format. See Bu::Logger::setFormat for details. | 113 | * Set the Bu::Logger format. See Bu::Logger::setFormat for details. |
114 | */ | 114 | */ |
115 | #define setLogFormat( sFrmt ) \ | 115 | #define setLogFormat( sFrmt ) \ |
116 | Bu::Logger::getInstance().setFormat( sFrmt ) | 116 | Bu::Logger::getInstance().setFormat( sFrmt ) |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Set the Bu::Logger logging mask simulating levels. See Bu::Logger::setLevel | 119 | * Set the Bu::Logger logging mask simulating levels. See Bu::Logger::setLevel |
120 | * for details. | 120 | * for details. |
121 | */ | 121 | */ |
122 | #define setLogLevel( nLevel ) \ | 122 | #define setLogLevel( nLevel ) \ |
123 | Bu::Logger::getInstance().setLevel( nLevel ) | 123 | Bu::Logger::getInstance().setLevel( nLevel ) |
124 | 124 | ||
125 | #endif | 125 | #endif |