Silicon
A realtime platform for creating interactive media.
Log.cpp
Go to the documentation of this file.
1// BSD 2-Clause License
2//
3// Copyright (c) 2022, Matthew McCall
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this
10// list of conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice,
13// this list of conditions and the following disclaimer in the documentation
14// and/or other materials provided with the distribution.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27#include <array>
28#include <memory>
29
30#include "spdlog/sinks/ringbuffer_sink.h"
31#include "spdlog/sinks/stdout_color_sinks.h"
32
33#include "Silicon/Config.hpp"
35#include "Silicon/Log.hpp"
36
38{
39public:
40 [[nodiscard]] static const LoggerManager &GetInstance()
41 {
42 static LoggerManager instance;
43 return instance;
44 }
45
47 {
48 return s_engineLogger;
49 }
51 {
52 return s_clientLogger;
53 }
54
55private:
57 {
58 s_engineLogHistory = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(64);
59 s_clientLogHistory = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(64);
60
62 std::make_shared<spdlog::sinks::stdout_color_sink_mt>(),
63 s_engineLogHistory};
64
66 std::make_shared<spdlog::sinks::stdout_color_sink_mt>(),
67 s_clientLogHistory};
68
69 s_engineLogger = std::make_shared<spdlog::logger>(Si::GetLocalized("Engine"), engineSinks.begin(), engineSinks.end());
70 s_clientLogger = std::make_shared<spdlog::logger>(Si::GetLocalized("Client"), clientSinks.begin(), clientSinks.end());
71
72 if constexpr (SI_BUILD_CONFIG == Si::BuildConfig::Debug)
73 {
74 s_engineLogger->set_level(spdlog::level::debug);
75 s_clientLogger->set_level(spdlog::level::debug);
76 }
77
78 s_engineLogger->set_pattern("%Y-%m-%dT%T [%n] %^%8l%$ %v");
79 s_clientLogger->set_pattern("%Y-%m-%dT%T [%n] %^%8l%$ %v");
80
81 s_engineLogHistory->set_pattern("%v");
82 s_clientLogHistory->set_pattern("%v");
83 }
84
87
90};
91
92namespace Si {
93
95{
97}
98
100{
102}
103
104}
T begin(T... args)
const std::shared_ptr< spdlog::logger > & getClientLogger() const
Definition: Log.cpp:50
static const LoggerManager & GetInstance()
Definition: Log.cpp:40
const std::shared_ptr< spdlog::logger > & getEngineLogger() const
Definition: Log.cpp:46
T end(T... args)
std::shared_ptr< spdlog::logger > GetEngineLogger()
Definition: Log.cpp:94
std::shared_ptr< spdlog::logger > GetClientLogger()
Definition: Log.cpp:99
Definition: Allocator.hpp:36
void Debug(Args &&... args)
Definition: Log.hpp:54
std::string GetLocalized(const std::string &key)