The small3d library
Tiny C++ 3D game development library for Win/MacOS/Linux/FreeBSD
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1
10#pragma once
11#include <iostream> // Included to construct ios_base::Init
12 // and avoid segmentation fault on Linux
13 // see https://coderedirect.com/questions/572522/c-segmentation-fault-when-using-cout-in-static-variable-initialization
14#include <ostream>
15#include <memory>
16
20#define LOGERROR(MESSAGE) logger->append(small3d::LogLevel::loggererror, MESSAGE)
21
25#define LOGINFO(MESSAGE) logger->append(small3d::LogLevel::loggerinfo, MESSAGE)
26
30#if defined(DEBUG) || defined(_DEBUG) || !defined (NDEBUG)
31#define LOGDEBUG(MESSAGE) logger->append(small3d::LogLevel::loggerdebug, MESSAGE)
32#else
33#define LOGDEBUG(MESSAGE)
34#endif
35
36namespace small3d {
37
42 enum class LogLevel {
43 loggerinfo, loggerdebug, loggererror
44 };
45
51 class Logger {
52 public:
53
59 Logger();
60
65 ~Logger();
66
74 void append(const LogLevel level, const std::string &message) const;
75 };
76
80 void initLogger();
81
85 void deleteLogger();
86}
87
91extern std::shared_ptr<small3d::Logger> logger;
std::shared_ptr< small3d::Logger > logger
The logger object used by the logging macros.
Definition Logger.cpp:14
Used for logging through macros (LOGERROR, LOGDEBUG, LOGINFO)
Definition Logger.hpp:51
void append(const LogLevel level, const std::string &message) const
Appends a message to the logger.
Definition Logger.cpp:26
Logger()
Constructor with stream for output.
Definition Logger.cpp:18
~Logger()
Destructor.
Definition Logger.cpp:22
Definition BinaryFile.hpp:15
LogLevel
Possible logging levels.
Definition Logger.hpp:42
void initLogger()
Initialise the logger.
Definition Logger.cpp:64
void deleteLogger()
Destroy the logger.
Definition Logger.cpp:68