52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#pragma once
|
|
#ifdef _SWITCH_
|
|
#include <switch.h>
|
|
#endif
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include <unistd.h>
|
|
#include <string>
|
|
#include <SDL.h>
|
|
#include <vector>
|
|
#include <time.h>
|
|
|
|
class Logger
|
|
{
|
|
public:
|
|
Logger(const Logger &) = delete;
|
|
Logger &operator=(const Logger &) = delete;
|
|
Logger(Logger &&) = delete;
|
|
Logger &operator=(Logger &&) = delete;
|
|
|
|
// 全局访问点
|
|
static Logger &GetInstance()
|
|
{
|
|
static Logger instance;
|
|
return instance;
|
|
}
|
|
|
|
public:
|
|
// 初始化函数 - 重定向SDL_Log到日志文件
|
|
bool Init();
|
|
|
|
// 关闭日志
|
|
void Close();
|
|
|
|
private:
|
|
Logger();
|
|
~Logger();
|
|
|
|
// SDL日志回调函数 - 将日志同时输出到文件和原始输出
|
|
static void SDLLogCallback(void* userdata, int category, SDL_LogPriority priority, const char* message);
|
|
|
|
// 获取当前时间字符串
|
|
std::string GetCurrentTime();
|
|
|
|
private:
|
|
FILE* m_logFile;
|
|
bool m_initialized;
|
|
SDL_LogOutputFunction m_originalCallback;
|
|
void* m_originalUserdata;
|
|
}; |