Unravel Engine C++ Reference
Loading...
Searching...
No Matches
logging.cpp
Go to the documentation of this file.
1#include "logging.h"
2
4#include <spdlog/sinks/basic_file_sink.h>
5#include <spdlog/sinks/stdout_color_sinks.h>
6
7#if UNRAVEL_PLATFORM_ANDROID
8#include <spdlog/sinks/android_sink.h>
9namespace spdlog
10{
11namespace sinks
12{
13using platform_sink_mt = android_sink_mt;
14using platform_sink_st = android_sink_st;
15} // namespace sinks
16} // namespace spdlog
17#else
18namespace spdlog
19{
20namespace sinks
21{
22using platform_sink_mt = stdout_color_sink_mt;
23using platform_sink_st = stdout_color_sink_st;
24} // namespace sinks
25} // namespace spdlog
26#endif
27
28namespace unravel
29{
30
31auto get_mutable_logging_container() -> std::shared_ptr<spdlog::sinks::dist_sink_mt>
32{
33 static auto sink = std::make_shared<spdlog::sinks::dist_sink_mt>();
34 return sink;
35}
36
37logging::logging(const std::string& output_file)
38{
39 spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [%n] %v"); // no %s/%#/%!
40
41 auto logging_container = get_mutable_logging_container();
42 auto console_sink = std::make_shared<spdlog::sinks::platform_sink_mt>();
43 auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(output_file, true);
44
45 logging_container->add_sink(console_sink);
46 logging_container->add_sink(file_sink);
47 auto logger = std::make_shared<spdlog::logger>(APPLOG, logging_container);
48 logger->flush_on(spdlog::level::err);
49 spdlog::initialize_logger(logger);
50 spdlog::set_level(spdlog::level::trace);
51}
52
54{
55 spdlog::shutdown();
56}
57} // namespace unravel
#define APPLOG
Definition logging.h:15
stdout_color_sink_st platform_sink_st
Definition logging.cpp:23
stdout_color_sink_mt platform_sink_mt
Definition logging.cpp:22
auto get_mutable_logging_container() -> std::shared_ptr< spdlog::sinks::dist_sink_mt >
Definition logging.cpp:31
logging(const std::string &output_file="Log.txt")
Definition logging.cpp:37