Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
Logger.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Platform.h"
4 #include "Singleton.hpp"
5 
6 #define SPDLOG_TRACE_ON
7 #define SPDLOG_DEBUG_ON
8 
9 #include "spdlog/spdlog.h"
10 #include "spdlog/sinks/stdout_sinks.h"
11 #include "spdlog/sinks/basic_file_sink.h"
12 #include "spdlog/async.h"
13 #include "spdlog/sinks/stdout_color_sinks.h"
14 
15 namespace Fling
16 {
21  class Logger : public Singleton<Logger>
22  {
23  public:
24 
25  virtual void Init() override;
26 
31  static std::shared_ptr<spdlog::logger> GetCurrentConsole();
32 
36  static std::shared_ptr<spdlog::logger> GetCurrentLogFile();
37 
38 
39  protected:
40 
42  static std::shared_ptr<spdlog::logger> m_Console;
43 
45  static std::shared_ptr<spdlog::logger> m_FileLog;
46 
47  };
48 
49 } // namespace Fling
50 
51 // Debug/release mode defs
52 #if defined( DEBUG ) || defined ( _DEBUG ) || defined ( F_ENABLE_LOGGING )
53 
54 #define F_LOG_TRACE( ... ) Logger::GetCurrentConsole()->info( __VA_ARGS__ ); Logger::GetCurrentLogFile()->info( __VA_ARGS__ )
55 #define F_LOG_WARN( ... ) Logger::GetCurrentConsole()->warn( __VA_ARGS__ ); Logger::GetCurrentLogFile()->warn( __VA_ARGS__ )
56 #define F_LOG_ERROR( ... ) Logger::GetCurrentConsole()->error( __VA_ARGS__ ); Logger::GetCurrentLogFile()->error( __VA_ARGS__ );
57 
60 #define F_LOG_FATAL( ... ) Logger::GetCurrentConsole()->error( __VA_ARGS__ ); \
61  throw std::runtime_error( __VA_ARGS__ )
62 
63 #else
64 
65 #define F_LOG_TRACE( ... )
66 #define F_LOG_WARN( ... )
67 #define F_LOG_ERROR( ... )
68 
71 #define F_LOG_FATAL( ... ) Logger::GetCurrentConsole()->error( __VA_ARGS__ ); \
72  throw std::runtime_error( __VA_ARGS__ )
73 #endif
static std::shared_ptr< spdlog::logger > m_Console
Pointer to the current console that is being used for logging.
Definition: Logger.h:42
static std::shared_ptr< spdlog::logger > GetCurrentLogFile()
Get the current async log file that is being written to.
Definition: Logger.cpp:42
virtual void Init() override
Definition: Logger.cpp:10
Class that can have only one instance.
Definition: Singleton.hpp:11
static std::shared_ptr< spdlog::logger > GetCurrentConsole()
Gets a reference to the current logging console
Definition: Logger.cpp:37
Singleton class that allows logging to the console as well as async to a file.
Definition: Logger.h:21
static std::shared_ptr< spdlog::logger > m_FileLog
Pointer to the log file logger.
Definition: Logger.h:45
Definition: Engine.h:13