4
// $Id: //poco/1.2/Foundation/include/Poco/LogStream.h#1 $
10
// Definition of the LogStream class.
12
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Foundation_LogStream_INCLUDED
40
#define Foundation_LogStream_INCLUDED
43
#include "Poco/Foundation.h"
44
#include "Poco/Logger.h"
45
#include "Poco/UnbufferedStreamBuf.h"
52
class Foundation_API LogStreamBuf: public UnbufferedStreamBuf
53
/// This class implements a streambuf interface
56
/// The streambuf appends all characters written to it
57
/// to a string. As soon as a CR or LF (std::endl) is written,
58
/// the string is sent to the Logger, with the set
62
LogStreamBuf(Logger& logger, Message::Priority priority);
63
/// Creates the LogStream.
66
/// Destroys the LogStream.
68
void setPriority(Message::Priority priority);
69
/// Sets the priority for log messages.
71
Message::Priority getPriority() const;
72
/// Returns the priority for log messages.
75
int writeToDevice(char c);
79
Message::Priority _priority;
84
class Foundation_API LogIOS: public virtual std::ios
85
/// The base class for LogStream.
87
/// This class is needed to ensure the correct initialization
88
/// order of the stream buffer and base classes.
91
LogIOS(Logger& logger, Message::Priority priority);
93
LogStreamBuf* rdbuf();
100
class Foundation_API LogStream: public LogIOS, public std::ostream
101
/// This class implements an ostream interface
104
/// The stream's buffer appends all characters written to it
105
/// to a string. As soon as a CR or LF (std::endl) is written,
106
/// the string is sent to the Logger, with the current
110
/// LogStream ls(someLogger);
111
/// ls << "Some informational message" << std::endl;
112
/// ls.error() << "Some error message" << std::endl;
115
LogStream(Logger& logger, Message::Priority priority = Message::PRIO_INFORMATION);
116
/// Creates the LogStream, using the given logger and priority.
118
LogStream(const std::string& loggerName, Message::Priority priority = Message::PRIO_INFORMATION);
119
/// Creates the LogStream, using the logger identified
120
/// by loggerName, and sets the priority.
123
/// Destroys the LogStream.
126
/// Sets the priority for log messages to Message::PRIO_FATAL.
128
LogStream& critical();
129
/// Sets the priority for log messages to Message::PRIO_CRITICAL.
132
/// Sets the priority for log messages to Message::PRIO_ERROR.
134
LogStream& warning();
135
/// Sets the priority for log messages to Message::PRIO_WARNING.
138
/// Sets the priority for log messages to Message::PRIO_NOTICE.
140
LogStream& information();
141
/// Sets the priority for log messages to Message::PRIO_INFORMATION.
144
/// Sets the priority for log messages to Message::PRIO_DEBUG.
147
/// Sets the priority for log messages to Message::PRIO_TRACE.
149
LogStream& priority(Message::Priority priority);
150
/// Sets the priority for log messages.
157
inline Message::Priority LogStreamBuf::getPriority() const
166
#endif // Foundation_LogStream_INCLUDED