新写的c++日志库:log4K
生活随笔
收集整理的這篇文章主要介紹了
新写的c++日志库:log4K
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
新寫的c++日志庫:log4K
網是開源的c/c++日志庫也不少,但用起來總覺得不方便,于是動手寫了一個C++日志框架Log4K。
測試代碼:
#include "log4k.h"#pragma comment(lib, "log4k.lib")static int g_Cnt = 0; void LogTestThread1(LPVOID lpPara) {DEBUG_FUNCTION();LOGFMTT(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTD(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTI(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTW(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTE(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);for (int i = 0; i < 10;){LOGFMTT(L"[%d] %s", i++, __FUNCTIONW__);//Sleep(10); } }void LogTestThread2(LPVOID lpPara) {DEBUG_FUNCTION();LOGFMTT_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTD(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTI_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTW(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTE_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);for (int i = 0; i < 10;){LOGFMTI(L"[%d] %s", i++, __FUNCTIONW__);//Sleep(10); } }int main() {DEBUG_FUNCTION();LOG4K_SET_OUT(Kevin55::OUT_TO_STDOUT_AND_LOG);LOGFMTT(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTD(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTI(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTW(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTE(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTT_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTD_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTI_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTW_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);LOGFMTE_A("----------Function:%s, Line:%d", __FUNCTION__, __LINE__);HANDLE hThread[2];ZeroMemory(hThread, sizeof(HANDLE) * 2);hThread[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LogTestThread1, NULL, 0, NULL);hThread[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LogTestThread2, NULL, 0, NULL);for (int i = 0; i < 100; i++){LOGFMTD(L"[%d]======%s", i, __FUNCTIONW__);}WaitForMultipleObjects(2, hThread, true, INFINITE);//LOG4K_SET_OUT(OUT_TO_STDOUT); LOGFMTT(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTD(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTI(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTW(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);LOGFMTE(L"----------Function:%s, Line:%d", __FUNCTIONW__, __LINE__);return 0; }?
使用nmake編譯及鏈接完成后,還有error信息,下面是所有nmake輸出:
cl /c /Zi /W3 /WX- /sdl /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /FoD:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\Log4K.obj /FdD:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\vc120.pdb /Gd /TP /analyze- /errorReport:prompt D:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\Log4K.cpp Log4K.cpplink /ERRORREPORT:PROMPT /OUT:D:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\Log4K.exe /INCREMENTAL /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib";"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /DEBUG /PDB:D:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\Log4K.pdp /LTCG /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /IMPLIB:D:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\Log4Z.lib /MACHINE:X86 D:\code\CPP_Code\KernalMainApp\Log4Z\Log4Z\out\log4k.obj LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification Generating code Finished generating codecl Log4K.cpp Log4K.cpp C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xlocale(337) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc Log4K.cpp(427) : error C2664: 'BOOL SetConsoleTitleA(LPCSTR)' : cannot convert argument 1 from 'const wchar_t [14]' to 'LPCSTR'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Log4K.cpp(513) : error C2664: 'DWORD GetModuleFileNameA(HMODULE,LPSTR,DWORD)' : cannot convert argument 2 from 'wchar_t [128]' to 'LPSTR'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast網上好像有人提交過類似的問題:https://connect.microsoft.com/VisualStudio/feedback/details/808657/vs2013-compiler-fails-on-function-templates-with-c-11-alternate-declaration-syntax,這個問題可能是編譯器的一個bug。
?
?
posted on 2015-08-11 12:57 kernel_main 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/kernel0815/p/4720690.html
總結
以上是生活随笔為你收集整理的新写的c++日志库:log4K的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle 12C -- trunca
- 下一篇: 动态创建的 CEdit 被限制长度,增加