Mantid
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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"
14
15#include <Poco/Message.h>
16#include <array>
17#include <iosfwd>
18#include <memory>
19#include <string>
20
21//----------------------------------------------------------------------
22// Forward declaration
23//----------------------------------------------------------------------
25namespace Poco {
26class Logger;
27}
29
30namespace Mantid {
31namespace Kernel {
32
51class MANTID_KERNEL_DLL Logger {
52public:
53 // Our logger's priority types are the same as POCO's Message's types.
54 using Priority = Poco::Message::Priority;
55
56 static const std::array<std::string, 9> PriorityNames;
57
59 Logger(const std::string &name);
61 void setName(const std::string &name);
62
64 void fatal(const std::string &msg);
66 void error(const std::string &msg);
68 void warning(const std::string &msg);
70 void notice(const std::string &msg);
72 void information(const std::string &msg);
74 void debug(const std::string &msg);
76 void accumulate(const std::string &msg);
78 void flush();
80 void flush(Priority);
81 void flushDebug();
82 void flushInformation();
83 void flushNotice();
84 void flushWarning();
85 void flushError();
86 void flushFatal();
87 void purge();
88
90 std::ostream &fatal();
92 std::ostream &error();
94 std::ostream &warning();
96 std::ostream &notice();
98 std::ostream &information();
100 std::ostream &debug();
101
103 void log(const std::string &message, const Priority &priority);
104
106 std::ostream &getLogStream(const Priority &priority);
107
109 void dump(const std::string &msg, const void *buffer, std::size_t length);
110
112 void setLevel(int level);
113
115 void setLevelOffset(int level);
116
118 int getLevelOffset() const;
119
121 int getLevel() const;
122
123 std::string getLevelName() const;
124
126 void setLevel(const std::string &level);
127
129 bool getEnabled() const;
130
132 void setEnabled(const bool enabled);
133
135 bool is(int level) const;
136
138 bool isDebug() const;
139
142 static void setLevelForAll(const int level);
143 static void setLevelForAll(const std::string &level);
144
146 static void shutdown();
147
148private:
149 // Disable default constructor
152 Logger(const Logger &);
155
157 Priority applyLevelOffset(Priority proposedLevel);
158
160 Poco::Logger *m_log;
162 std::unique_ptr<ThreadSafeLogStream> m_logStream;
163
168};
169
170} // namespace Kernel
171} // namespace Mantid
std::string name
Definition Run.cpp:60
double error
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
bool m_enabled
The state of this logger, disabled loggers send no messages.
Definition Logger.h:167
Poco::Message::Priority Priority
Definition Logger.h:54
Poco::Logger * m_log
Internal handle to third party logging objects.
Definition Logger.h:160
Logger & operator=(const Logger &)
Disable assignment.
std::unique_ptr< ThreadSafeLogStream > m_logStream
Allows stream operators for a logger.
Definition Logger.h:162
static const std::array< std::string, 9 > PriorityNames
Definition Logger.h:56
Logger(const Logger &)
Disable copying.
int m_levelOffset
The offset of the logger.
Definition Logger.h:165
Helper class which provides the Collimation Length for SANS instruments.