Mantid
Loading...
Searching...
No Matches
ThreadSafeLogStream.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//--------------------------------------------
10// Includes
11//--------------------------------------------
12#include "MantidKernel/DllConfig.h"
13
14#include <Poco/LogStream.h>
15#include <Poco/Message.h>
16#include <Poco/Thread.h>
17
18#include <iosfwd>
19#include <map>
20#include <mutex>
21#include <string>
22
23// Forward Declare
24namespace Poco {
25class Logger;
26}
27
28namespace Mantid {
29namespace Kernel {
41class MANTID_KERNEL_DLL ThreadSafeLogStreamBuf : public Poco::LogStreamBuf {
42public:
44 ThreadSafeLogStreamBuf(Poco::Logger &logger, Poco::Message::Priority priority);
45 int overflow(char c);
46 using Poco::LogStreamBuf::overflow;
47 void accumulate(const std::string &message);
48 std::string flush();
49
50private:
52 int writeToDevice(char c) override;
53
54private:
56 std::map<Poco::Thread::TID, std::string> m_messages;
58 std::map<Poco::Thread::TID, std::string> m_accumulator;
60 std::mutex m_mutex;
61};
62
70class MANTID_KERNEL_DLL ThreadSafeLogIOS : public virtual std::ios {
71public:
73 ThreadSafeLogIOS(Poco::Logger &logger, Poco::Message::Priority priority);
74 // Return a pointer to the stream buffer object
75 Poco::LogStreamBuf *rdbuf();
76
77protected:
80};
81
97class MANTID_KERNEL_DLL ThreadSafeLogStream : public ThreadSafeLogIOS, public std::ostream {
98public:
100 ThreadSafeLogStream(Poco::Logger &logger, Poco::Message::Priority priority = Poco::Message::PRIO_INFORMATION);
101
104 ThreadSafeLogStream(const std::string &loggerName,
105 Poco::Message::Priority priority = Poco::Message::PRIO_INFORMATION);
107 ThreadSafeLogStream &fatal();
110 ThreadSafeLogStream &fatal(const std::string &message);
112 ThreadSafeLogStream &critical();
115 ThreadSafeLogStream &critical(const std::string &message);
120 ThreadSafeLogStream &error(const std::string &message);
122 ThreadSafeLogStream &warning();
125 ThreadSafeLogStream &warning(const std::string &message);
127 ThreadSafeLogStream &notice();
130 ThreadSafeLogStream &notice(const std::string &message);
132 ThreadSafeLogStream &information();
135 ThreadSafeLogStream &information(const std::string &message);
137 ThreadSafeLogStream &debug();
140 ThreadSafeLogStream &debug(const std::string &message);
142 ThreadSafeLogStream &priority(Poco::Message::Priority priority);
144 ThreadSafeLogStream &accumulate(const std::string &message);
146 std::string flush();
147};
148} // namespace Kernel
149} // namespace Mantid
double error
Definition: IndexPeaks.cpp:133
The base class for ThreadSafeLogStream.
ThreadSafeLogStreamBuf m_buf
The log stream buffer object.
This class implements a threadsafe version of the POCO buffer interface to a Logger's stream object.
std::map< Poco::Thread::TID, std::string > m_messages
Store a map of thread indices to messages.
std::map< Poco::Thread::TID, std::string > m_accumulator
Store a map of thread indices to accummulators of messages.
std::mutex m_mutex
mutex protecting logstream
The main log stream class implementing an ostream interface to a Logger.
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30