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

22
src/util/format/log.h

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

Loading…
Cancel
Save