Index

zydeco / 0dc574e

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
203 Aug 2023 22:030dc574eC++ bringup; SDL window creationJosh Stockin1500G

Blob @ zydeco / src / util / Logger.cpp

text/plain1215 bytesdownload raw
1#include <fmt/core.h>
2
3#include "ZydecoCommon.hpp"
4#include "Logger.hpp"
5
6static Logger LOGGER("LOGGER");
7
8// static initialize members
9std::ostream *Logger::s_ostream = nullptr;
10Logger::Verbosity Logger::s_maxVerbosity = Logger::DEBUG;
11
12
13static const char *VERBOSITY_STRINGS[] = {
14 "", // DISABLED
15 "\e[1;031m[ERROR]\e[0m",
16 "\e[1;033m[WARNING]\e[0m",
17 "\e[1;034m[INFO]\e[0m",
18 "\e[1;035m[DEBUG]\e[0m",
19 "\e[1;036m[VERBOSE]\e[0m",
20 "\e[1;037m[TRACE]\e[0m",
21};
22
23// ctor
24Logger::Logger(std::string logger_name):
25 m_loggerName(logger_name)
26{
27
28}
29
30// should be called once
31void Logger::InitializeLogging(Verbosity max_verbosity, std::ostream *stream)
32{
33 if (stream != nullptr)
34 {
35 s_maxVerbosity = max_verbosity;
36 s_ostream = stream;
37
38 std::string message = fmt::format("Initialized logger with max verbosity {0}", VERBOSITY_STRINGS[max_verbosity]);
39 LOGGER.Log(INFO, message);
40 }
41}
42
43// output debug message
44void Logger::Log(Verbosity verbosity, std::string message)
45{
46 if (s_ostream != nullptr && verbosity <= s_maxVerbosity)
47 {
48 *s_ostream << VERBOSITY_STRINGS[verbosity] << " \e[090m" << m_loggerName << "\e[0m: " << message << "\n";
49 }
50}
51