The small3d library
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 
36 namespace 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 
91 extern std::shared_ptr<small3d::Logger> logger;
small3d::Logger::append
void append(const LogLevel level, const std::string &message) const
Appends a message to the logger.
Definition: Logger.cpp:26
small3d::Logger
Used for logging through macros (LOGERROR, LOGDEBUG, LOGINFO)
Definition: Logger.hpp:51
small3d::LogLevel
LogLevel
Possible logging levels.
Definition: Logger.hpp:42
small3d::Logger::~Logger
~Logger()
Destructor.
Definition: Logger.cpp:22
small3d::Logger::Logger
Logger()
Constructor with stream for output.
Definition: Logger.cpp:18
logger
std::shared_ptr< small3d::Logger > logger
The logger object used by the logging macros.
Definition: Logger.cpp:14
small3d::initLogger
void initLogger()
Initialise the logger.
Definition: Logger.cpp:64
small3d
Definition: BinaryFile.hpp:15
small3d::deleteLogger
void deleteLogger()
Destroy the logger.
Definition: Logger.cpp:68