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 #include "spdlog/fmt/fmt.h"
15 #include "spdlog/fmt/ostr.h"
16 
17 namespace Fling
18 {
23  class Logger : public Singleton<Logger>
24  {
25  public:
26 
27  virtual void Init() override;
28 
33  static std::shared_ptr<spdlog::logger> GetCurrentConsole();
34 
38  static std::shared_ptr<spdlog::logger> GetCurrentLogFile();
39 
40 
41  protected:
42 
44  static std::shared_ptr<spdlog::logger> m_Console;
45 
47  static std::shared_ptr<spdlog::logger> m_FileLog;
48 
49  };
50 
51 } // namespace Fling
52 
53 // Debug/release mode defs
54 #if FLING_DEBUG || defined ( F_ENABLE_LOGGING )
55 
56 #define F_LOG_TRACE( ... ) Fling::Logger::GetCurrentConsole()->info( __VA_ARGS__ ); Fling::Logger::GetCurrentLogFile()->info( __VA_ARGS__ )
57 #define F_LOG_WARN( ... ) Fling::Logger::GetCurrentConsole()->warn( __VA_ARGS__ ); Fling::Logger::GetCurrentLogFile()->warn( __VA_ARGS__ )
58 #define F_LOG_ERROR( ... ) Fling::Logger::GetCurrentConsole()->error( __VA_ARGS__ ); Fling::Logger::GetCurrentLogFile()->error( __VA_ARGS__ );
59 
62 #define F_LOG_FATAL( ... ) Fling::Logger::GetCurrentConsole()->error( __VA_ARGS__ ); \
63  throw std::runtime_error( __VA_ARGS__ )
64 
65 #else
66 
67 #define F_LOG_TRACE( ... )
68 #define F_LOG_WARN( ... )
69 #define F_LOG_ERROR( ... )
70 
73 #define F_LOG_FATAL( ... ) Fling::Logger::GetCurrentConsole()->error( __VA_ARGS__ ); \
74  throw std::runtime_error( __VA_ARGS__ )
75 #endif
static std::shared_ptr< spdlog::logger > m_Console
Pointer to the current console that is being used for logging.
Definition: Logger.h:44
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:23
static std::shared_ptr< spdlog::logger > m_FileLog
Pointer to the log file logger.
Definition: Logger.h:47
Definition: Engine.h:29