修改日志格式

This commit is contained in:
DevWiki 2024-10-08 16:17:26 +08:00
parent 8e1a01215d
commit d784fc6570
4 changed files with 93 additions and 15 deletions

View File

@ -1,20 +1,75 @@
#include "Log.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_sinks.h"
#include <spdlog/logger.h>
#include <spdlog/sinks/stdout_color_sinks.h>
std::shared_ptr<spdlog::logger> WinDevice::Log::logger = nullptr;
void WinDevice::Log::Init(LogLevel level, std::string fileName)
{
spdlog::stdout_logger_mt("console");
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
logger = spdlog::stdout_color_mt("console");
logger->set_level(static_cast<spdlog::level::level_enum>(level));
logger->set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
// spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
// spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
}
void WinDevice::Log::Info(std::string format, std::string args...)
void WinDevice::Log::debug(std::string format)
{
logger->debug(format);
}
void WinDevice::Log::WInfo(std::wstring format, std::wstring args...)
void WinDevice::Log::debug(std::string format, std::string args...)
{
logger->debug(format, args);
}
void WinDevice::Log::debugW(std::wstring format, std::wstring args...)
{
logger->debug(format, args);
}
void WinDevice::Log::info(std::string format)
{
logger->info(format);
}
void WinDevice::Log::info(std::string format, std::string args...)
{
logger->info(format, args);
}
void WinDevice::Log::infoW(std::wstring format, std::wstring args...)
{
logger->info(format, args);
}
void WinDevice::Log::warn(std::string format)
{
logger->warn(format);
}
void WinDevice::Log::warn(std::string format, std::string args...)
{
logger->warn(format, args);
}
void WinDevice::Log::warnW(std::wstring format, std::wstring args...)
{
logger->warn(format, args);
}
void WinDevice::Log::error(std::string format)
{
logger->error(format);
}
void WinDevice::Log::error(std::string format, std::string args...)
{
logger->error(format, args);
}
void WinDevice::Log::errorW(std::wstring format, std::wstring args...)
{
logger->error(format, args);
}

View File

@ -1,5 +1,8 @@
#pragma once
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_sinks.h"
#include <spdlog/sinks/stdout_color_sinks.h>
#define LOG_FUNC_START() spdlog::info("=====> {0} start <=====", __FUNCTION__)
#define LOG_FUNC_END() spdlog::info("=====> {0} end <=====", __FUNCTION__)
@ -16,8 +19,24 @@ namespace WinDevice {
public:
static void Init(LogLevel level, std::string fileName);
static void Info(std::string format, std::string args...);
static void WInfo(std::wstring format, std::wstring args...);
static void debug(std::string format);
static void debug(std::string format, std::string args...);
static void debugW(std::wstring format, std::wstring args...);
static void info(std::string format);
static void info(std::string format, std::string args...);
static void infoW(std::wstring format, std::wstring args...);
static void warn(std::string format);
static void warn(std::string format, std::string args...);
static void warnW(std::wstring format, std::wstring args...);
static void error(std::string format);
static void error(std::string format, std::string args...);
static void errorW(std::wstring format, std::wstring args...);
private:
static std::shared_ptr<spdlog::logger> logger;
};
}

View File

@ -4,6 +4,8 @@
#include "../Utils/Log.h"
#include <dxgi.h>
using namespace WinDevice;
WinDevice::ScreenManager::ScreenManager()
{
@ -123,12 +125,12 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
}
else
{
spdlog::info("Failed to get display resolution.");
Log::error("Failed to get display resolution.");
}
}
else
{
spdlog::info("Failed to get display device info.");
spdlog::error("Failed to get display device info.");
}
return TRUE;
}

View File

@ -5,6 +5,7 @@
#include <thread>
#include "Video/ScreenManager.h"
#include "Utils/PerformanceTool.h"
#include "Utils/Log.h"
void getInfo() {
@ -20,9 +21,10 @@ void getInfo() {
}
int main() {
// WinDevice::ScreenManager screenManager;
// screenManager.UpdateDisplayInfo();
getInfo();
WinDevice::Log::Init(WinDevice::LogLevel::Debug, "");
WinDevice::ScreenManager screenManager;
screenManager.UpdateDisplayInfo();
// getInfo();
std::cout << "Press Enter to exit..." << std::endl; // 输出提示信息
std::cin.get(); // 等待用户输入
return 0;