Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Logger.hpp
1#pragma once
2
3#include <string>
4#include <fstream>
5#include <sstream>
6#include <vector>
7
8// Fix for Windows headers.
9#ifdef ERROR
10# undef ERROR
11#endif
12
17class Log {
18
19public:
21 enum Domain {
22 GPU = 0,
24 Input,
25 Utilities,
26 Config
27 };
28
29private:
31 enum class Level : int {
32 INFO = 0,
33 WARNING,
34 ERROR,
35 VERBOSE
36 };
37
42 void set(Level l);
43
44 const std::vector<std::string> _domainStrings = {"GPU", "Resources", "Input", "Utilities", "Config"};
45
46 const std::vector<std::string> _levelStrings = {"", "(!) ", "(X) ", ""};
47
48 const std::vector<std::string> _colorStrings = {"\x1B[0m\x1B[39m", "\x1B[0m\x1B[33m", "\x1B[0m\x1B[31m", "\x1B[2m\x1B[37m"};
49
50public:
52 Log();
53
59 Log(const std::string & filePath, bool logToStdin, bool verbose = false);
60
64 void setVerbose(bool verbose);
65
70 template<class T>
71 Log & operator<<(const T & input) {
73 _stream << input;
74 return *this;
75 }
76
82 Log & operator<<(const Domain & domain);
83
88 Log & operator<<(std::ostream & (*modif)(std::ostream &));
89
94 Log & operator<<(std::ios_base & (*modif)(std::ios_base &));
95
102 static void setDefaultFile(const std::string & filePath);
103
107 static void setDefaultVerbose(bool verbose);
108
112 static Log & Info();
113
117 static Log & Warning();
118
122 static Log & Error();
123
127 static Log & Verbose();
128
131private:
136 void setFile(const std::string & filePath, bool flushExisting = true);
137
140 void flush();
141
144 void appendIfNeeded();
145
146 Level _level = Level::INFO;
147 bool _logToStdOut = true;
148 std::ofstream _file;
149 std::stringstream _stream;
150 bool _verbose = false;
151 bool _ignoreUntilFlush = false;
152 bool _appendPrefix = false;
153 bool _useColors = false;
154
156};
Contains configurable elements as attributes, populated from the command line, a configuration file o...
Definition: Config.hpp:25
Provide utility functions to communicate with the driver and GPU.
Definition: GPU.hpp:20
The input manager is responsible for updating the internal input states (keyboard,...
Definition: Input.hpp:10
Provides logging utilities, either to the standard/error output or to a file, with multiple criticali...
Definition: Logger.hpp:17
void setVerbose(bool verbose)
Definition: Logger.cpp:96
void setFile(const std::string &filePath, bool flushExisting=true)
Definition: Logger.cpp:79
bool _logToStdOut
Should the logs be output to standard output.
Definition: Logger.hpp:147
bool _verbose
Is the logger verbose.
Definition: Logger.hpp:150
const std::vector< std::string > _colorStrings
Colors prefix strings.
Definition: Logger.hpp:48
Domain
Domain prefix that will be appended before a line.
Definition: Logger.hpp:21
Log & operator<<(const T &input)
Definition: Logger.hpp:71
bool _useColors
Should color formatting be used.
Definition: Logger.hpp:153
void flush()
Definition: Logger.cpp:128
bool _appendPrefix
Should a domain or level prefix be appended to the current line.
Definition: Logger.hpp:152
static Log * _defaultLogger
Default static logger.
Definition: Logger.hpp:155
bool _ignoreUntilFlush
Internal flag to ignore the current line if it is verbose.
Definition: Logger.hpp:151
static Log & Warning()
Definition: Logger.cpp:113
const std::vector< std::string > _domainStrings
Domain prefix strings.
Definition: Logger.hpp:44
static Log & Info()
Definition: Logger.cpp:108
static Log & Verbose()
Definition: Logger.cpp:123
std::ofstream _file
The output log file stream.
Definition: Logger.hpp:148
std::stringstream _stream
Internal log string stream.
Definition: Logger.hpp:149
void appendIfNeeded()
Definition: Logger.cpp:150
void set(Level l)
Definition: Logger.cpp:24
static void setDefaultFile(const std::string &filePath)
Definition: Logger.cpp:100
const std::vector< std::string > _levelStrings
Levels prefix strings.
Definition: Logger.hpp:46
Level
Criticality level.
Definition: Logger.hpp:31
@ VERBOSE
Will only be logged if verbose is enabled.
Level _level
The current criticality level.
Definition: Logger.hpp:146
static void setDefaultVerbose(bool verbose)
Definition: Logger.cpp:104
static Log & Error()
Definition: Logger.cpp:118
Log()
Definition: Logger.cpp:34
The Resources manager is responsible for all resources loading and setup.
Definition: ResourcesManager.hpp:48