添加项目文件。
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
// 确保引入包含日志宏和 GlobalServerLogger 的头文件
|
||||
#include "../UNSWebServerCore/ServerLogger.h"
|
||||
|
||||
#ifndef __FILENAME__
|
||||
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#endif
|
||||
|
||||
// 仅用于提供函数指针地址
|
||||
void DummyPureFunction() {}
|
||||
|
||||
int main() {
|
||||
// 【步骤 1】初始化控制台日志,开启最低级别
|
||||
SCLOG_CONSOLE_INIT(uns::llTrace);
|
||||
|
||||
SCLOG_SHORT_INFO("=== ServerLogger Macro-based Test Started ===");
|
||||
|
||||
// =================================================================
|
||||
// 1. C++ fmt 风格测试 (带 F 的宏)
|
||||
// =================================================================
|
||||
SCLOG_SHORT_TRACE("\n--- [Part 1: FMT Style Macros Test] ---");
|
||||
{
|
||||
// 基础类型
|
||||
SCLOGF_INFO("Base values (Long): int={}, double={}, string={}, bool={}, wstring={}",
|
||||
42, 3.14159, std::string("UNS_Core日志测试"), true, L"wstring防乱码测试");
|
||||
SCLOGF_SHORT_DEBUG("Base values (Short): int={}, long={}, string={}",
|
||||
1024, 2147483648, "ShortFormatTest");
|
||||
|
||||
// 容器 (Range)
|
||||
std::vector<int> dummy_vector = {10, 20, 30, 40};
|
||||
SCLOGF_DEBUG("Vector lazy contents: {}", dummy_vector);
|
||||
|
||||
// 键值对 (Pair)
|
||||
std::pair<std::string, double> dummy_pair = {"Database_Connections", 12.0};
|
||||
SCLOGF_WARNING("Metric data pair: {}", dummy_pair);
|
||||
|
||||
// 函数/闭包 (Function)
|
||||
std::function<void()> func1(DummyPureFunction);
|
||||
auto dummy_closure = [status = 500]() { return status; };
|
||||
std::function func2 = dummy_closure;
|
||||
SCLOGF_ERROR("Registered handlers - Pure: {}, Closure: {}", func1, func2);
|
||||
|
||||
// 时间
|
||||
using Clock = std::chrono::system_clock;
|
||||
// 1. 获取当前系统时间
|
||||
Clock::time_point current_time = Clock::now();
|
||||
// 2. 测试不同精度的时间点
|
||||
Clock::time_point future_time = current_time + std::chrono::hours(24);
|
||||
// 3. 纯粹的时间格式化打印测试
|
||||
SCLOGF_INFO("--- Time Wrapper Verification ---");
|
||||
SCLOGF_INFO("Current System Time : {:%Y-%m-%d %H:%M:%S}", current_time);
|
||||
SCLOGF_INFO("Future Task Due Time: {:%H:%M:%S}", future_time);
|
||||
SCLOGF_INFO("Custom Date Format : {:%Y/%m/%d}", current_time);
|
||||
|
||||
std::time_t raw_time = std::time(nullptr);
|
||||
std::tm* time_info = std::localtime(&raw_time);
|
||||
if (time_info != nullptr)
|
||||
{
|
||||
// 复制一份值对象传给日志,确保生命周期安全
|
||||
std::tm current_tm = *time_info;
|
||||
SCLOGF_INFO("--- TM Struct Verification ---");
|
||||
SCLOGF_INFO("Current Time (TM) : {:%Y-%m-%d %H:%M:%S}", current_tm);
|
||||
SCLOGF_INFO("Custom Date (TM) : {:%Y/%m/%d}", current_tm);
|
||||
SCLOGF_INFO("Pure Time (TM) : {:%H:%M:%S}", current_tm);
|
||||
}
|
||||
|
||||
// 4. Duration 格式化测试(基础单位)
|
||||
SCLOGF_INFO("--- Duration Wrapper Verification ---");
|
||||
|
||||
std::chrono::nanoseconds dur_ns(123);
|
||||
std::chrono::microseconds dur_us(4567);
|
||||
std::chrono::milliseconds dur_ms(8901);
|
||||
std::chrono::seconds dur_s(65);
|
||||
|
||||
// 基础单位测试
|
||||
SCLOGF_INFO("Nanoseconds : {}", dur_ns);
|
||||
SCLOGF_INFO("Microseconds : {}", dur_us);
|
||||
SCLOGF_INFO("Milliseconds : {}", dur_ms);
|
||||
SCLOGF_INFO("Seconds : {}", dur_s);
|
||||
|
||||
// 5. Duration 自动升档测试(关键)
|
||||
std::chrono::seconds dur_s2(3600 + 120 + 5); // 1h 2m 5s
|
||||
std::chrono::minutes dur_m(90); // 1h 30m
|
||||
std::chrono::hours dur_h(48); // 2d
|
||||
|
||||
SCLOGF_INFO("--- Duration Auto Scaling ---");
|
||||
SCLOGF_INFO("Mixed Seconds : {}", dur_s2);
|
||||
SCLOGF_INFO("Minutes Overflow : {}", dur_m);
|
||||
SCLOGF_INFO("Hours Overflow : {}", dur_h);
|
||||
|
||||
// 6. 高精度 duration 测试(纳秒级)
|
||||
std::chrono::nanoseconds high_ns(1234567890123LL);
|
||||
|
||||
SCLOGF_INFO("--- High Precision Duration ---");
|
||||
SCLOGF_INFO("Large Nanosec : {}", high_ns);
|
||||
|
||||
// 7. 负载/极值测试(防止溢出或异常)
|
||||
std::chrono::nanoseconds zero_ns(0);
|
||||
std::chrono::nanoseconds near_us(999);
|
||||
std::chrono::nanoseconds near_ms(999999);
|
||||
|
||||
SCLOGF_INFO("--- Edge Cases ---");
|
||||
SCLOGF_INFO("Zero Duration : {}", zero_ns);
|
||||
SCLOGF_INFO("Near Micro Bound : {}", near_us);
|
||||
SCLOGF_INFO("Near Milli Bound : {}", near_ms);
|
||||
|
||||
// 混合复杂编排
|
||||
std::vector<int> scores = {99, 95, 88};
|
||||
SCLOGF_FATAL("Critical failure! Operator: '{}', Cluster Nodes: {}, Error Code: {}",
|
||||
"RootAdmin", scores, 5005);
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// 2. 传统 printf 风格测试 (不带 F 的宏)
|
||||
// =================================================================
|
||||
SCLOG_SHORT_TRACE("\n--- [Part 2: Printf Style Macros Test] ---");
|
||||
{
|
||||
// 2.1 测试带文件行号的长日志宏 (SCLOG_xxx)
|
||||
SCLOG_TRACE("Printf Trace log: msg=%s, val=%d", "TraceMessage", 100);
|
||||
SCLOG_DEBUG("Printf Debug log: score=%.2f", 98.5);
|
||||
SCLOG_INFO("Printf Info log: hex=0x%X", 0xAB);
|
||||
SCLOG_WARNING("Printf Warning log: active=%s", "true");
|
||||
SCLOG_ERROR("Printf Error log: connection count=%d", 5);
|
||||
SCLOG_FATAL("Printf Fatal log: system exit code=%d", -1);
|
||||
|
||||
// 2.2 测试不带文件行号的短日志宏 (SCLOG_SHORT_xxx)
|
||||
SCLOG_SHORT_TRACE("Printf Short Trace: code=%d", 1);
|
||||
SCLOG_SHORT_DEBUG("Printf Short Debug: name=%s", "WorkerA");
|
||||
SCLOG_SHORT_INFO("Printf Short Info: load=%d%%", 85);
|
||||
SCLOG_SHORT_WARNING("Printf Short Warning: threshold=%.1f", 90.0);
|
||||
SCLOG_SHORT_ERROR("Printf Short Error: mask=0x%x", 0xFF00);
|
||||
SCLOG_SHORT_FATAL("Printf Short Fatal: panic id=%d", 999);
|
||||
}
|
||||
|
||||
SCLOG_SHORT_TRACE("");
|
||||
SCLOG_SHORT_INFO("=== ServerLogger Macro-based Test Completed ===");
|
||||
|
||||
for(int i = 5; i > 0; i--)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
SCLOGF_SHORT_INFO("Close Log Stream in {} Seconds", i);
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
|
||||
// 【步骤 2】退出前关闭日志流
|
||||
SCLOGF_SHORT_INFO("Log Stream Closed");
|
||||
SCLOG_CLOSE();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>18.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{bf89fe01-6bba-4c4c-b9b1-3daf5ef2b7f3}</ProjectGuid>
|
||||
<RootNamespace>TestLogger</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_WINDOWS;UNSWEBSERVERCORE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\UNSWebServerCore\LogArg.cpp" />
|
||||
<ClCompile Include="..\UNSWebServerCore\ServerLogger.cpp" />
|
||||
<ClCompile Include="TestLogger.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\UNSWebServerCore\Export.h" />
|
||||
<ClInclude Include="..\UNSWebServerCore\LogArg.h" />
|
||||
<ClInclude Include="..\UNSWebServerCore\ServerLogger.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="TestLogger.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\UNSWebServerCore\LogArg.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\UNSWebServerCore\ServerLogger.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\UNSWebServerCore\LogArg.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\UNSWebServerCore\ServerLogger.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\UNSWebServerCore\Export.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user