22
33#include < singleton.h>
44
5- #include < iostream>
65#include < memory>
76#include < string>
8-
9- #include < spdlog/spdlog.h>
10- #include < spdlog/sinks/stdout_color_sinks.h>
11- #include < spdlog/async.h>
12- #include < fmt/core.h>
13-
14- constexpr const char * kMainLogger = " spectator" ;
7+ #include < format>
158
169class Logger final : public Singleton<Logger>
1710{
1811 private:
19- std::shared_ptr<spdlog::logger> m_logger;
12+ // Forward declaration for pimpl
13+ class LoggerImpl ;
14+ std::unique_ptr<LoggerImpl> m_impl;
2015
2116 friend class Singleton <Logger>;
2217
23- Logger ()
24- {
25- try
26- {
27- m_logger = spdlog::create_async_nb<spdlog::sinks::ansicolor_stdout_sink_mt>(kMainLogger );
28- }
29- catch (const spdlog::spdlog_ex& ex)
30- {
31- std::cerr << " Log initialization failed: " << ex.what () << " \n " ;
32- m_logger = nullptr ;
33- }
34- }
35-
36- ~Logger () = default ;
18+ Logger ();
19+ ~Logger ();
3720 Logger (const Logger&) = delete ;
3821 Logger& operator =(const Logger&) = delete ;
3922 Logger (Logger&&) = delete ;
4023 Logger& operator =(Logger&&) = delete ;
4124
4225 public:
43- static spdlog::logger* GetLogger () { return GetInstance ().m_logger .get (); }
44-
45- static void debug (const std::string& msg)
46- {
47- GetLogger ()->debug (msg);
48- }
49-
50- static void info (const std::string& msg)
51- {
52- GetLogger ()->info (msg);
53- }
54-
55- static void warn (const std::string& msg)
56- {
57- GetLogger ()->warn (msg);
58- }
59-
60- static void error (const std::string& msg)
61- {
62- GetLogger ()->error (msg);
63- }
26+ static void debug (const std::string& msg);
27+ static void info (const std::string& msg);
28+ static void warn (const std::string& msg);
29+ static void error (const std::string& msg);
6430
6531 template <typename ... Args>
66- static void debug (fmt ::format_string<Args...> fmt, Args&&... args)
32+ static void debug (std ::format_string<Args...> fmt, Args&&... args)
6733 {
68- GetLogger ()-> debug (fmt, std::forward<Args>(args)...);
34+ debug (std::format ( fmt, std::forward<Args>(args)...) );
6935 }
7036
7137 template <typename ... Args>
72- static void info (fmt ::format_string<Args...> fmt, Args&&... args)
38+ static void info (std ::format_string<Args...> fmt, Args&&... args)
7339 {
74- GetLogger ()-> info (fmt, std::forward<Args>(args)...);
40+ info (std::format ( fmt, std::forward<Args>(args)...) );
7541 }
7642
7743 template <typename ... Args>
78- static void warn (fmt ::format_string<Args...> fmt, Args&&... args)
44+ static void warn (std ::format_string<Args...> fmt, Args&&... args)
7945 {
80- GetLogger ()-> warn (fmt, std::forward<Args>(args)...);
46+ warn (std::format ( fmt, std::forward<Args>(args)...) );
8147 }
8248
8349 template <typename ... Args>
84- static void error (fmt ::format_string<Args...> fmt, Args&&... args)
50+ static void error (std ::format_string<Args...> fmt, Args&&... args)
8551 {
86- GetLogger ()-> error (fmt, std::forward<Args>(args)...);
52+ error (std::format ( fmt, std::forward<Args>(args)...) );
8753 }
88- };
54+ };
0 commit comments