author | Tero Marttila <terom@fixme.fi> |
Thu, 22 Jan 2009 04:24:26 +0200 | |
changeset 425 | 567144562978 |
parent 418 | 194bc810a570 |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef LOGGER_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define LOGGER_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
4 |
#include "Types.hh" |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
5 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
6 |
#include <iostream> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
7 |
|
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
224
diff
changeset
|
8 |
/** |
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
9 |
* Utility class used for logging, use Engine::log() to construct these. Implements the same streaming behaviour as |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
10 |
* std::ostream, but the construtor prints out a header, and the destructor a newline. |
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
224
diff
changeset
|
11 |
* |
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
12 |
* Useage example: |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
13 |
* |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
14 |
* \code |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
15 |
* Engine::log(INFO, "foo.bar") << "value of quux=" << quux; |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
16 |
* |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
17 |
* \endcode |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
18 |
* |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
19 |
* This will result in output like the following to stdout: |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
20 |
* |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
21 |
* \verbatim |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
22 |
* INFO [foo.bar] value of quux=5 |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
23 |
* \endverbatim |
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
224
diff
changeset
|
24 |
* |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
224
diff
changeset
|
25 |
* @see Engine::log |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
224
diff
changeset
|
26 |
*/ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
27 |
class Logger { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
28 |
private: |
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
29 |
/** |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
30 |
* The stream we output to |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
31 |
*/ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
32 |
std::ostream &stream; |
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
33 |
|
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
34 |
/** |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
35 |
* Do we even care? |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
36 |
*/ |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
37 |
bool show; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
38 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
39 |
public: |
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
40 |
/** |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
41 |
* If the given level is smaller than the given maximum level, output the header. Otherwise, act as a |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
42 |
* no-op. |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
43 |
*/ |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
44 |
Logger (std::ostream &stream, LogLevel level, const char *module, LogLevel max_level); |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
45 |
|
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
46 |
/** |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
47 |
* Stream the given value to our output stream, just like with std::ostream, unless we're acting as a no-op. |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
48 |
*/ |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
49 |
template <typename T> Logger& operator<< (const T val); |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
50 |
|
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
51 |
/** |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
52 |
* Output the final newline |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
53 |
*/ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
~Logger (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
55 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
56 |
|
418
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
57 |
/* |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
58 |
* Logger template method definition |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
59 |
*/ |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
60 |
template <typename T> |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
61 |
inline Logger& Logger::operator<< (const T val) { |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
62 |
if (show) |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
63 |
stream << val; |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
64 |
|
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
65 |
// chaining |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
66 |
return *this; |
194bc810a570
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents:
365
diff
changeset
|
67 |
} |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
68 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
69 |
#endif /* LOGGER_HH */ |