ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Log.h
浏览该文件的文档.
1#pragma once
2
3#include <memory>
4#include <utility>
5
6#include <spdlog/spdlog.h>
7#include <spdlog/sinks/stdout_color_sinks.h>
8#include <spdlog/fmt/ostr.h>
9#include "Core.h"
10
11namespace Shit {
15 class SHIT_API Log {
16 public:
17 static bool Init(); //初始化日志
18
19 //静态调用API
20 template<typename... Args>
21 inline static void Trace(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->trace(fmt, std::forward<Args>(args)...); }
22
23 template<typename... Args>
24 inline static void Debug(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->debug(fmt, std::forward<Args>(args)...); }
25
26 template<typename... Args>
27 inline static void Info(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->info(fmt, std::forward<Args>(args)...); }
28
29 template<typename... Args>
30 inline static void Warn(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->warn(fmt, std::forward<Args>(args)...); }
31
32 template<typename... Args>
33 inline static void Error(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->error(fmt, std::forward<Args>(args)...); }
34
35 template<typename... Args>
36 inline static void Critical(fmt::format_string<Args...> fmt, Args&&... args) { s_ClientLogger->critical(fmt, std::forward<Args>(args)...); }
37
38 inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
39 inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
40
41 private:
42 static std::shared_ptr<spdlog::logger> s_CoreLogger;
43 static std::shared_ptr<spdlog::logger> s_ClientLogger;
44 };
45}
46
47// Core 日志宏
48#define ST_CORE_TRACE(...) ::Shit::Log::GetCoreLogger()->trace(__VA_ARGS__)
49#define ST_CORE_DEBUG(...) ::Shit::Log::GetCoreLogger()->debug(__VA_ARGS__)
50#define ST_CORE_INFO(...) ::Shit::Log::GetCoreLogger()->info(__VA_ARGS__)
51#define ST_CORE_WARN(...) ::Shit::Log::GetCoreLogger()->warn(__VA_ARGS__)
52#define ST_CORE_ERROR(...) ::Shit::Log::GetCoreLogger()->error(__VA_ARGS__)
53#define ST_CORE_CRITICAL(...) ::Shit::Log::GetCoreLogger()->critical(__VA_ARGS__)
54
55//Client 日志宏
56#define ST_TRACE(...) ::Shit::Log::GetClientLogger()->trace(__VA_ARGS__)
57#define ST_DEBUG(...) ::Shit::Log::GetClientLogger()->debug(__VA_ARGS__)
58#define ST_INFO(...) ::Shit::Log::GetClientLogger()->info(__VA_ARGS__)
59#define ST_WARN(...) ::Shit::Log::GetClientLogger()->warn(__VA_ARGS__)
60#define ST_ERROR(...) ::Shit::Log::GetClientLogger()->error(__VA_ARGS__)
61#define ST_CRITICAL(...) ::Shit::Log::GetClientLogger()->critical(__VA_ARGS__)
#define SHIT_API
定义 Core.h:12
日志封装类
定义 Log.h:15
static std::shared_ptr< spdlog::logger > & GetCoreLogger()
定义 Log.h:38
static void Trace(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:21
static void Debug(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:24
static void Error(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:33
static void Warn(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:30
static std::shared_ptr< spdlog::logger > & GetClientLogger()
定义 Log.h:39
static void Info(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:27
static bool Init()
static void Critical(fmt::format_string< Args... > fmt, Args &&... args)
定义 Log.h:36
定义 AudioPlayer.h:9