Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JMessageStream.hh
Go to the documentation of this file.
1#ifndef __JLOGGER__JMESSAGESTREAM__
2#define __JLOGGER__JMESSAGESTREAM__
3
4#include <ostream>
5#include <sstream>
6
8
9
10/**
11 * \file
12 * Message reporting compatible with STL output stream operations.
13 * \author mdejong
14 */
15namespace JLOGGER {}
16namespace JPP { using namespace JLOGGER; }
17
18namespace JLOGGER {
19
20 /**
21 * Message streamer.
22 *
23 * This class can be used in the same way as the STL ostream operator.\n
24 * The actual message is reported on detruction of the object, e.g:
25 *
26 * JStreamLogger logger(std::cout);
27 *
28 * JDebugStream (logger) << "This is a debug message " << hex << 15;
29 *
30 * will produce on the terminal:
31 *
32 * <tt>"... This is a debug message f"</tt>
33 *
34 * where <tt>...</tt> stands for the message prefix (see class JMessageLogger).
35 * The list of available message streamer classes includes:
36 *
37 * - JDebugStream
38 * - JWarningStream
39 * - JErrorStream
40 * - JNoticeStream
41 * - JStatusStream
42 */
44 public std::ostringstream
45 {
46 public:
47 /**
48 * Appends value to internal buffer.
49 *
50 * \param value value
51 * \return this JMessageStream
52 */
53 template<class T>
54 JMessageStream& operator<<(const T& value)
55 {
56 static_cast<std::ostringstream&>(*this) << value;
57
58 return *this;
59 }
60
61
62 /**
63 * Type definition of I/O operator.
64 */
65 typedef std::ostream& (*io_manip) (std::ostream&);
66
67
68 /**
69 * Append I/O manipulator.
70 *
71 * \param manip I/O manipulator
72 * \return this JMessageStream
73 */
75 {
76 static_cast<std::ostringstream&>(*this) << manip;
77
78 return *this;
79 }
80
81 protected:
82 /**
83 * Constructor.
84 *
85 * \param __logger message logger
86 * \param __typeout logger method
87 */
89 void (JMessageLogger::*__typeout)(const std::string&)) :
90 std::ostringstream(),
91 logger (__logger),
92 typeout(__typeout)
93 {}
94
95
96 /**
97 * Report message.
98 */
100 {
101 (logger.*typeout)(this->str());
102 }
103
104
106 void (JMessageLogger::*typeout)(const std::string&);
107 };
108
109
110 /**
111 * Level specific message streamers.
112 */
118}
119
120#endif
General purpose message reporting.
void error(const JMessage_t &message)
void warning(const JMessage_t &message)
void debug(const JMessage_t &message)
void status(const JMessage_t &message)
void notice(const JMessage_t &message)
void(JMessageLogger::* typeout)(const std::string &)
JMessageStream(JMessageLogger &__logger, void(JMessageLogger::*__typeout)(const std::string &))
Constructor.
~JMessageStream()
Report message.
JMessageStream & operator<<(io_manip manip)
Append I/O manipulator.
JMessageStream & operator<<(const T &value)
Appends value to internal buffer.
std::ostream &(*) io_manip(std::ostream &)
Type definition of I/O operator.
Message logging.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Level specific message streamers.
JDebugStream(JMessageLogger &logger)
JErrorStream(JMessageLogger &logger)
JNoticeStream(JMessageLogger &logger)
JStatusStream(JMessageLogger &logger)
JWarningStream(JMessageLogger &logger)