Implemented command-line option for setting the output log priority.
This commit is contained in:
@@ -29,7 +29,7 @@ class Logger
|
||||
ColorStream &errorStream();
|
||||
|
||||
// The level from which on messages should be printed
|
||||
void setOutputPriority(Priority outputLevel);
|
||||
void setLogPriority(Priority logPriority);
|
||||
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
|
||||
|
||||
void log(Priority priority, const char *message);
|
||||
@@ -39,7 +39,7 @@ class Logger
|
||||
ColorStream m_outputStream;
|
||||
ColorStream m_errorStream;
|
||||
|
||||
Priority m_outputPriority;
|
||||
Priority m_logPriority;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#ifndef __ANTHEM__OUTPUT__PRIORITY_H
|
||||
#define __ANTHEM__OUTPUT__PRIORITY_H
|
||||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
|
||||
namespace anthem
|
||||
{
|
||||
namespace output
|
||||
@@ -22,6 +25,41 @@ enum class Priority
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline constexpr const char *priorityName(Priority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case Priority::Debug:
|
||||
return "debug";
|
||||
case Priority::Info:
|
||||
return "info";
|
||||
case Priority::Warning:
|
||||
return "warning";
|
||||
case Priority::Error:
|
||||
return "error";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline Priority priorityFromName(const char *priorityName)
|
||||
{
|
||||
if (std::strcmp(priorityName, "debug") == 0)
|
||||
return Priority::Debug;
|
||||
if (std::strcmp(priorityName, "info") == 0)
|
||||
return Priority::Info;
|
||||
if (std::strcmp(priorityName, "warning") == 0)
|
||||
return Priority::Warning;
|
||||
if (std::strcmp(priorityName, "error") == 0)
|
||||
return Priority::Error;
|
||||
|
||||
throw std::runtime_error("unknown log priority");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user