12#include <Poco/Logger.h>
13#include <Poco/StreamUtil.h>
14#include <Poco/UnbufferedStreamBuf.h>
26 :
Poco::LogStreamBuf(logger, priority), m_messages() {}
38 if (c ==
'\n' || c ==
'\r') {
39 Poco::Message msg(logger().name(),
m_messages[Poco::Thread::currentTid()], getPriority());
43 std::lock_guard<std::mutex> lock(
m_mutex);
46 return static_cast<int>(c);
54 std::lock_guard<std::mutex> lock(
m_mutex);
63 const std::string returnValue =
m_accumulator[Poco::Thread::currentTid()];
64 std::lock_guard<std::mutex> lock(
m_mutex);
78 poco_ios_init(&
m_buf);
119 m_buf.logger().fatal(message);
120 return priority(Poco::Message::PRIO_FATAL);
136 m_buf.logger().critical(message);
137 return priority(Poco::Message::PRIO_CRITICAL);
153 m_buf.logger().error(message);
154 return priority(Poco::Message::PRIO_ERROR);
170 m_buf.logger().warning(message);
171 return priority(Poco::Message::PRIO_WARNING);
187 m_buf.logger().notice(message);
188 return priority(Poco::Message::PRIO_NOTICE);
204 m_buf.logger().information(message);
205 return priority(Poco::Message::PRIO_INFORMATION);
221 m_buf.logger().debug(message);
222 return priority(Poco::Message::PRIO_DEBUG);
The Logger class is in charge of the publishing messages from the framework through various channels.
The base class for ThreadSafeLogStream.
Poco::LogStreamBuf * rdbuf()
Return the underlying buffer for this stream.
ThreadSafeLogIOS(Poco::Logger &logger, Poco::Message::Priority priority)
Constructor.
ThreadSafeLogStreamBuf m_buf
The log stream buffer object.
std::map< Poco::Thread::TID, std::string > m_messages
Store a map of thread indices to messages.
int writeToDevice(char c) override
Overridden from base to write to the device in a thread-safe manner.
std::map< Poco::Thread::TID, std::string > m_accumulator
Store a map of thread indices to accummulators of messages.
std::string flush()
Returns and flushes the accumulated message.
ThreadSafeLogStreamBuf(Poco::Logger &logger, Poco::Message::Priority priority)
Constructor.
void accumulate(const std::string &message)
accumulate a message to the thread safe accummulator.
std::mutex m_mutex
mutex protecting logstream
The main log stream class implementing an ostream interface to a Logger.
ThreadSafeLogStream & warning()
Sets the priority for log messages to Poco::Message::PRIO_WARNING.
ThreadSafeLogStream & fatal()
Sets the priority for log messages to Poco::Message::PRIO_FATAL.
ThreadSafeLogStream & error()
Sets the priority for log messages to Poco::Message::PRIO_ERROR.
std::string flush()
Returns and flushes the accumulated messages.
ThreadSafeLogStream & accumulate(const std::string &message)
accumulates the message to the accummulator buffer
ThreadSafeLogStream & notice()
Sets the priority for log messages to Poco::Message::PRIO_NOTICE.
ThreadSafeLogStream & critical()
Sets the priority for log messages to Poco::Message::PRIO_CRITICAL.
ThreadSafeLogStream & information()
Sets the priority for log messages to Poco::Message::PRIO_INFORMATION.
ThreadSafeLogStream & priority(Poco::Message::Priority priority)
Sets the priority for log messages.
ThreadSafeLogStream(Poco::Logger &logger, Poco::Message::Priority priority=Poco::Message::PRIO_INFORMATION)
Creates the ThreadSafeLogStream, using the given logger and priority.
ThreadSafeLogStream & debug()
Sets the priority for log messages to Poco::Message::PRIO_DEBUG.