myproject 0.0.0
%%description%%
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1#pragma once
2
3#include <spdlog/sinks/basic_file_sink.h>
4#include <spdlog/sinks/stdout_color_sinks.h>
5#include <spdlog/spdlog.h>
6
7#include <memory>
8
9#include "base.h"
10#include "parameters.h"
11#include "singleton.h"
12
13namespace myproject {
14
16class Logger final : public Singleton<Logger> {
17 public:
19 Logger(const Logger&) = delete;
20 Logger& operator=(const Logger&) = delete;
21 Logger(Logger&&) = delete;
22 Logger& operator=(Logger&&) = delete;
24 spdlog::drop_all(); // Release all Loggers
25 }
26
28 void initLogger() {
31 parameters::log_path, false);
32
33 m_ConsoleSink->set_level(spdlog::level::trace);
34 m_FileSink->set_level(spdlog::level::trace);
35
36 m_ConsoleSink->set_pattern("[%H:%M:%S.%e] [%^%l%$] [t:%t] [%s:%#] %v");
37 m_FileSink->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [%s:%#] %v");
38
39 m_Sinks.emplace_back(m_ConsoleSink);
40 m_Sinks.emplace_back(m_FileSink);
41
42 m_Logger =
43 CreateRef<spdlog::logger>("rs_log", begin(m_Sinks), end(m_Sinks));
44 m_Logger->set_level(spdlog::level::trace);
45 m_Logger->flush_on(
46 spdlog::level::warn); // Flush automatically when warning appears
47
48 spdlog::register_logger(m_Logger); // Register Logger
49 spdlog::set_default_logger(m_Logger);
50 }
51
52 private:
53 Ref<spdlog::logger> m_Logger;
56 std::vector<spdlog::sink_ptr> m_Sinks{};
57}; // Logger
58
59} // namespace myproject
The Logger class is a singleton that manages the application logging.
Definition logger.h:16
Logger & operator=(Logger &&)=delete
Logger()
Definition logger.h:18
Logger & operator=(const Logger &)=delete
Logger(const Logger &)=delete
void initLogger()
Creates SPDLOG logger with multiple sinks (console + file).
Definition logger.h:28
Logger(Logger &&)=delete
~Logger()
Definition logger.h:23
Definition singleton.h:8
Definition application.cpp:63
std::shared_ptr< T > Ref
Definition base.h:16
constexpr Ref< T > CreateRef(Args &&... args)
Definition base.h:18