修改日志格式
This commit is contained in:
parent
8e1a01215d
commit
d784fc6570
@ -1,20 +1,75 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include <spdlog/logger.h>
|
||||||
#include "spdlog/sinks/stdout_sinks.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)
|
void WinDevice::Log::Init(LogLevel level, std::string fileName)
|
||||||
{
|
{
|
||||||
spdlog::stdout_logger_mt("console");
|
logger = spdlog::stdout_color_mt("console");
|
||||||
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
|
logger->set_level(static_cast<spdlog::level::level_enum>(level));
|
||||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
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);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "spdlog/spdlog.h"
|
#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_START() spdlog::info("=====> {0} start <=====", __FUNCTION__)
|
||||||
#define LOG_FUNC_END() spdlog::info("=====> {0} end <=====", __FUNCTION__)
|
#define LOG_FUNC_END() spdlog::info("=====> {0} end <=====", __FUNCTION__)
|
||||||
@ -16,8 +19,24 @@ namespace WinDevice {
|
|||||||
public:
|
public:
|
||||||
static void Init(LogLevel level, std::string fileName);
|
static void Init(LogLevel level, std::string fileName);
|
||||||
|
|
||||||
static void Info(std::string format, std::string args...);
|
static void debug(std::string format);
|
||||||
static void WInfo(std::wstring format, std::wstring args...);
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../Utils/Log.h"
|
#include "../Utils/Log.h"
|
||||||
#include <dxgi.h>
|
#include <dxgi.h>
|
||||||
|
|
||||||
|
using namespace WinDevice;
|
||||||
|
|
||||||
WinDevice::ScreenManager::ScreenManager()
|
WinDevice::ScreenManager::ScreenManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -123,12 +125,12 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spdlog::info("Failed to get display resolution.");
|
Log::error("Failed to get display resolution.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spdlog::info("Failed to get display device info.");
|
spdlog::error("Failed to get display device info.");
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Video/ScreenManager.h"
|
#include "Video/ScreenManager.h"
|
||||||
#include "Utils/PerformanceTool.h"
|
#include "Utils/PerformanceTool.h"
|
||||||
|
#include "Utils/Log.h"
|
||||||
|
|
||||||
void getInfo() {
|
void getInfo() {
|
||||||
|
|
||||||
@ -20,9 +21,10 @@ void getInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// WinDevice::ScreenManager screenManager;
|
WinDevice::Log::Init(WinDevice::LogLevel::Debug, "");
|
||||||
// screenManager.UpdateDisplayInfo();
|
WinDevice::ScreenManager screenManager;
|
||||||
getInfo();
|
screenManager.UpdateDisplayInfo();
|
||||||
|
// getInfo();
|
||||||
std::cout << "Press Enter to exit..." << std::endl; // 输出提示信息
|
std::cout << "Press Enter to exit..." << std::endl; // 输出提示信息
|
||||||
std::cin.get(); // 等待用户输入
|
std::cin.get(); // 等待用户输入
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user