Jpp
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 
7 #include "JMessageLogger.hh"
8 
9 
10 /**
11  * \file
12  * Message reporting compatible with STL output stream operations.
13  * \author mdejong
14  */
15 namespace JLOGGER {}
16 namespace JPP { using namespace JLOGGER; }
17 
18 namespace 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
JLOGGER::JDebugStream
Level specific message streamers.
Definition: JMessageStream.hh:113
JLOGGER::JNoticeStream
Definition: JMessageStream.hh:116
JLOGGER::JMessageLogger
Message logger.
Definition: JMessageLogger.hh:53
JLOGGER::JMessageStream::typeout
void(JMessageLogger::* typeout)(const std::string &)
Definition: JMessageStream.hh:106
JLOGGER::JMessageStream
Message streamer.
Definition: JMessageStream.hh:43
JLOGGER::JErrorStream::JErrorStream
JErrorStream(JMessageLogger &logger)
Definition: JMessageStream.hh:115
JLOGGER::JErrorStream
Definition: JMessageStream.hh:115
JLOGGER::JStatusStream::JStatusStream
JStatusStream(JMessageLogger &logger)
Definition: JMessageStream.hh:117
JLOGGER
Message logging.
Definition: JControlHostLogger.hh:14
JLOGGER::JMessageStream::operator<<
JMessageStream & operator<<(const T &value)
Appends value to internal buffer.
Definition: JMessageStream.hh:54
JLOGGER::JMessageLogger::debug
void debug(const JMessage_t &message)
Definition: JMessageLogger.hh:182
JLOGGER::JMessageLogger::warning
void warning(const JMessage_t &message)
Definition: JMessageLogger.hh:183
JLOGGER::JMessageStream::logger
JMessageLogger & logger
Definition: JMessageStream.hh:105
JLOGGER::JMessageStream::~JMessageStream
~JMessageStream()
Report message.
Definition: JMessageStream.hh:99
JLOGGER::JMessageLogger::error
void error(const JMessage_t &message)
Definition: JMessageLogger.hh:184
JLOGGER::JMessageLogger::status
void status(const JMessage_t &message)
Definition: JMessageLogger.hh:186
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLOGGER::JMessageStream::io_manip
std::ostream &(* io_manip)(std::ostream &)
Type definition of I/O operator.
Definition: JMessageStream.hh:65
JLOGGER::JNoticeStream::JNoticeStream
JNoticeStream(JMessageLogger &logger)
Definition: JMessageStream.hh:116
JLOGGER::JWarningStream
Definition: JMessageStream.hh:114
JLOGGER::JStatusStream
Definition: JMessageStream.hh:117
JLOGGER::JMessageLogger::notice
void notice(const JMessage_t &message)
Definition: JMessageLogger.hh:185
JLOGGER::JMessageStream::JMessageStream
JMessageStream(JMessageLogger &__logger, void(JMessageLogger::*__typeout)(const std::string &))
Constructor.
Definition: JMessageStream.hh:88
JLOGGER::JMessageStream::operator<<
JMessageStream & operator<<(io_manip manip)
Append I/O manipulator.
Definition: JMessageStream.hh:74
std
Definition: jaanetDictionary.h:36
JLOGGER::JWarningStream::JWarningStream
JWarningStream(JMessageLogger &logger)
Definition: JMessageStream.hh:114
JLOGGER::JDebugStream::JDebugStream
JDebugStream(JMessageLogger &logger)
Definition: JMessageStream.hh:113
JMessageLogger.hh