Browse Source

Util: Rename logging type enum, Type -> LogType

master
Riyyi 2 years ago
parent
commit
eb25e98f79
  1. 32
      src/util/format/log.cpp
  2. 22
      src/util/format/log.h

32
src/util/format/log.cpp

@ -17,31 +17,31 @@ std::string formatTimeElapsed()
return format("{:.3}s ", s_timer.elapsedNanoseconds() / 1000000000.0);
}
std::string formatType(Type type)
std::string formatType(LogType type)
{
std::string output;
formatTo(output, "[");
switch (type) {
case Type::Trace:
case LogType::Trace:
formatTo(output, "trace");
break;
case Type::Debug:
case LogType::Debug:
formatTo(output, fg(TerminalColor::Magenta), "debug");
break;
case Type::Success:
case LogType::Success:
formatTo(output, fg(TerminalColor::Green), "success");
break;
case Type::Info:
case LogType::Info:
formatTo(output, fg(TerminalColor::Blue), "info");
break;
case Type::Warn:
case LogType::Warn:
formatTo(output, Emphasis::Bold | fg(TerminalColor::Yellow), "warn");
break;
case Type::Error:
case LogType::Error:
formatTo(output, Emphasis::Bold | fg(TerminalColor::Red), "error");
break;
case Type::Critical:
case LogType::Critical:
formatTo(output, Emphasis::Bold | fg(TerminalColor::White) | bg(TerminalColor::Red), "critical");
break;
default:
@ -54,7 +54,7 @@ std::string formatType(Type type)
// -----------------------------------------
LogOperatorStyle::LogOperatorStyle(FILE* file, Type type)
LogOperatorStyle::LogOperatorStyle(FILE* file, LogType type)
: m_file(file)
, m_type(type)
, m_stream()
@ -73,37 +73,37 @@ LogOperatorStyle::~LogOperatorStyle()
LogOperatorStyle trace()
{
return LogOperatorStyle(stdout, Type::Trace);
return LogOperatorStyle(stdout, LogType::Trace);
}
LogOperatorStyle debug()
{
return LogOperatorStyle(stdout, Type::Debug);
return LogOperatorStyle(stdout, LogType::Debug);
}
LogOperatorStyle success()
{
return LogOperatorStyle(stdout, Type::Success);
return LogOperatorStyle(stdout, LogType::Success);
}
LogOperatorStyle info()
{
return LogOperatorStyle(stdout, Type::Info);
return LogOperatorStyle(stdout, LogType::Info);
}
LogOperatorStyle warn()
{
return LogOperatorStyle(stderr, Type::Warn);
return LogOperatorStyle(stderr, LogType::Warn);
}
LogOperatorStyle error()
{
return LogOperatorStyle(stderr, Type::Error);
return LogOperatorStyle(stderr, LogType::Error);
}
LogOperatorStyle critical()
{
return LogOperatorStyle(stderr, Type::Critical);
return LogOperatorStyle(stderr, LogType::Critical);
}
} // namespace Util::Format

22
src/util/format/log.h

@ -18,7 +18,7 @@ namespace Util::Format {
static Util::Timer s_timer;
enum class Type : uint8_t {
enum class LogType : uint8_t {
Trace, // White
Debug, // Purple
Success, // Green
@ -29,7 +29,7 @@ enum class Type : uint8_t {
};
std::string formatTimeElapsed();
std::string formatType(Type type);
std::string formatType(LogType type);
#define LOG_FUNCTION(name, file, type) \
template<size_t N, typename... Parameters> \
@ -42,26 +42,26 @@ std::string formatType(Type type);
print(file, "\n"); \
}
LOG_FUNCTION(trace, stdout, Type::Trace);
LOG_FUNCTION(debug, stdout, Type::Debug);
LOG_FUNCTION(success, stdout, Type::Success);
LOG_FUNCTION(info, stdout, Type::Info);
LOG_FUNCTION(warn, stderr, Type::Warn);
LOG_FUNCTION(error, stderr, Type::Error);
LOG_FUNCTION(critical, stderr, Type::Critical);
LOG_FUNCTION(trace, stdout, LogType::Trace);
LOG_FUNCTION(debug, stdout, LogType::Debug);
LOG_FUNCTION(success, stdout, LogType::Success);
LOG_FUNCTION(info, stdout, LogType::Info);
LOG_FUNCTION(warn, stderr, LogType::Warn);
LOG_FUNCTION(error, stderr, LogType::Error);
LOG_FUNCTION(critical, stderr, LogType::Critical);
// -----------------------------------------
class LogOperatorStyle {
public:
LogOperatorStyle(FILE* file, Type type);
LogOperatorStyle(FILE* file, LogType type);
virtual ~LogOperatorStyle();
Builder& builder() { return m_builder; }
private:
FILE* m_file;
Type m_type;
LogType m_type;
std::stringstream m_stream;
Builder m_builder;

Loading…
Cancel
Save