9#include <Poco/Logger.h>
10#include <Poco/NullStream.h>
20Poco::NullOutputStream NULL_STREAM;
22int fixLevel(
const int level) {
31int toLevel(
const std::string &level) {
33 std::string lowercase(level);
34 std::transform(level.cbegin(), level.cend(), lowercase.begin(), [](
unsigned char c) { return std::tolower(c); });
37 if (lowercase ==
"not_used") {
48 std::stringstream msg;
49 msg <<
"Do not know how to convert \"" << level <<
"\" to an integer level";
50 throw std::runtime_error(msg.str());
56const std::array<std::string, 9>
Logger::PriorityNames{
"none",
"fatal",
"critical",
"error",
"warning",
57 "notice",
"information",
"debug",
"trace"};
70 auto *logger = &Poco::Logger::get(
name);
71 auto logStream = std::make_unique<ThreadSafeLogStream>(*logger);
160void Logger::dump(
const std::string &msg,
const void *buffer, std::size_t length) {
163 m_log->dump(msg, buffer, length);
164 }
catch (std::exception &e) {
167 std::cerr << e.what();
180 retVal =
m_log->is(level);
181 }
catch (std::exception &e) {
184 std::cerr << e.what();
193 const int levelActual = fixLevel(level);
194 m_log->setLevel(levelActual);
195 }
catch (std::exception &e) {
198 std::cerr << e.what() <<
"\n";
208 const int int_level = toLevel(level);
209 m_log->setLevel(int_level);
210 }
catch (std::exception &e) {
213 std::cerr << e.what() <<
"\n";
220 const auto level = std::size_t(this->
getLevel());
325 Poco::Logger::shutdown();
326 }
catch (std::exception &e) {
329 std::cerr << e.what();
338 const int levelActual = fixLevel(level);
342 Poco::Logger::setLevel(
"", levelActual);
343 }
catch (std::exception &e) {
346 std::cerr << e.what();
351 int intLevel = toLevel(level);
365 case Poco::Message::PRIO_FATAL:
366 m_log->fatal(message);
368 case Poco::Message::PRIO_CRITICAL:
369 m_log->critical(message);
371 case Poco::Message::PRIO_ERROR:
372 m_log->error(message);
374 case Poco::Message::PRIO_WARNING:
375 m_log->warning(message);
377 case Poco::Message::PRIO_NOTICE:
378 m_log->notice(message);
380 case Poco::Message::PRIO_INFORMATION:
381 m_log->information(message);
383 case Poco::Message::PRIO_DEBUG:
384 m_log->debug(message);
386 case Poco::Message::PRIO_TRACE:
387 m_log->trace(message);
392 }
catch (std::exception &e) {
395 std::cerr <<
"Error in logging framework: " << e.what();
409 case Poco::Message::PRIO_FATAL:
412 case Poco::Message::PRIO_CRITICAL:
415 case Poco::Message::PRIO_ERROR:
418 case Poco::Message::PRIO_WARNING:
421 case Poco::Message::PRIO_NOTICE:
424 case Poco::Message::PRIO_INFORMATION:
427 case Poco::Message::PRIO_DEBUG:
441 int retVal = proposedLevel;
444 return proposedLevel;
447 if (retVal <
static_cast<int>(Priority::PRIO_FATAL)) {
448 retVal = Priority::PRIO_FATAL;
449 }
else if (retVal >
static_cast<int>(Priority::PRIO_TRACE)) {
450 retVal = Priority::PRIO_TRACE;
The Logger class is in charge of the publishing messages from the framework through various channels.
void flushInformation()
flushes the accumulated message with information priority
void flushFatal()
flushes the accumulated message with fatal priority
void dump(const std::string &msg, const void *buffer, std::size_t length)
Logs the given message at debug level, followed by the data in buffer.
void setName(const std::string &name)
Update the name of the logger.
std::ostream & error()
Logs at error level.
int getLevelOffset() const
Gets the Logger's log offset level.
static void setLevelForAll(const int level)
Sets the log level for all Loggers created so far, including the root logger.
bool m_enabled
The state of this logger, disabled loggers send no messages.
static void shutdown()
Shuts down the logging framework and releases all Loggers.
void flushDebug()
flushes the accumulated message with debug priority
Priority applyLevelOffset(Priority proposedLevel)
Return a log stream set with the given priority.
std::string getLevelName() const
void setEnabled(const bool enabled)
set if the logging is enabled
void flushError()
flushes the accumulated message with error priority
bool isDebug() const
Returns true if log level is at least debug.
Poco::Message::Priority Priority
void log(const std::string &message, const Priority &priority)
Log a message at a given priority.
void setLevel(int level)
Sets the Logger's log level.
std::ostream & getLogStream(const Priority &priority)
gets the correct log stream for a priority
Poco::Logger * m_log
Internal handle to third party logging objects.
int getLevel() const
Returns the Logger's log level.
bool getEnabled() const
returns true if the log is enabled
std::ostream & warning()
Logs at warning level.
bool is(int level) const
Returns true if at least the given log level is set.
std::ostream & debug()
Logs at debug level.
void setLevelOffset(int level)
Sets the Logger's log offset level.
std::ostream & notice()
Logs at notice level.
std::ostream & information()
Logs at information level.
std::unique_ptr< ThreadSafeLogStream > m_logStream
Allows stream operators for a logger.
std::ostream & fatal()
Logs at Fatal level.
static const std::array< std::string, 9 > PriorityNames
void purge()
flushes the accumulated messages without logging them
void flush()
flushes accumulated messages to the current level
void flushWarning()
flushes the accumulated message with warning priority
int m_levelOffset
The offset of the logger.
void flushNotice()
flushes the accumulated message with notice priority
void accumulate(const std::string &msg)
accumulates a message
The main log stream class implementing an ostream interface to a Logger.
void swap(MultiFileValidator &obj1, MultiFileValidator &obj2)