Index

zydeco / 0dd781a

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
405 Aug 2023 20:500dd781aCreate event handling and threads structureJosh Stockin112G

Blob @ zydeco / src / util / Logger.cpp

text/plain1163 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 LOGGER.Log(INFO, "Initialized logger with max verbosity {0}", VERBOSITY_STRINGS[max_verbosity]);
39 }
40}
41
42// output debug message
43void Logger::Log(Verbosity verbosity, std::string message)
44{
45 if (s_ostream != nullptr && verbosity <= s_maxVerbosity)
46 {
47 *s_ostream << VERBOSITY_STRINGS[verbosity] << " \e[090m" << m_loggerName << "\e[0m: " << message << "\n";
48 }
49}
50