From 6865afce40b47735db3316827031b025d06187fd Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 25 May 2021 22:20:08 +0800 Subject: [PATCH] no message --- CMakeLists.txt | 10 +++++----- general/inc/loger.h | 5 +++-- general/inc/utils.h | 6 ------ general/src/loger.cpp | 35 ++++++++++++++++++++++++++++++++++- test/src/cpp11/CMakeLists.txt | 4 ++++ test/src/cpp11/cpp11_test.cpp | 8 ++++++-- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24c7b7d..4af4dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,15 +22,15 @@ endif() # copy header files SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj) set(COPYITEM inc) -file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*) +file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/general/inc/*) file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message("include dir " ${INCLUDES}) +message("include dir \n" ${INCLUDES}) file(GLOB PatternINCLUDES ${PROJECT_SOURCE_DIR}/general/src/pattern/*) file(COPY ${PatternINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/pattern FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message( "copy pattern library" ${PatternINCLUDES}) +message( "copy pattern library \n" ${PatternINCLUDES}) file(GLOB EncryptINCLUDES ${PROJECT_SOURCE_DIR}/general/src/encrypt/*.h) file(COPY ${EncryptINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/encrypt FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) @@ -38,11 +38,11 @@ file(GLOB MathINCLUDES ${PROJECT_SOURCE_DIR}/general/src/math/*.hpp) message( "copy math library" ${MathINCLUDES}) add_custom_command(TARGET generallib PRE_LINK COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/general/src/math/eigen ${LIBRARY_OUTPUT_PATH}/inc/math/eigen) -message( "copy third library") +message( "copy third library \n") file(GLOB THIRD ${PROJECT_SOURCE_DIR}/general/third/include/*) file(COPY ${THIRD} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/third/include/ FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message( "copy net ") +message( "copy net \n") file(GLOB NET ${PROJECT_SOURCE_DIR}/general/src/net/*.h) file(COPY ${NET} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ diff --git a/general/inc/loger.h b/general/inc/loger.h index 2f54c0c..2ae2523 100644 --- a/general/inc/loger.h +++ b/general/inc/loger.h @@ -14,6 +14,7 @@ using namespace std; namespace Loger{ + typedef enum Mode{ Mode_Daily, // 每天保存一次日志 MODE_Monthly, // 每个月保存一次日志 @@ -30,8 +31,8 @@ namespace Loger{ public: _C_Loger(FILE *p); _C_Loger(string path); - - int Debug(); + + int Debug(string,string,int); int Log(); int LogFile(); void operator+(const string&); diff --git a/general/inc/utils.h b/general/inc/utils.h index c24db45..340b4c4 100644 --- a/general/inc/utils.h +++ b/general/inc/utils.h @@ -1,21 +1,15 @@ // // Created by 29019 on 2019/5/2. // - #ifndef CUTILS_UTILS_H #define CUTILS_UTILS_H - - - - #include #include "debug.h" #include using namespace std; - typedef enum { ENV_WINDOWS = 1, ENV_LINUX, diff --git a/general/src/loger.cpp b/general/src/loger.cpp index 7586814..bfb8161 100644 --- a/general/src/loger.cpp +++ b/general/src/loger.cpp @@ -21,6 +21,36 @@ string getTime() return string(tmp); } +int _C_Loger::Debug(string dat,string function,int line){ + // 还没有过天 + if(getTimeDate() == this->mCurrentDate){ + string tmp = getTime(); + tmp += ":"; + tmp += dat; + tmp += "at [" + function + " line " + std::to_string(line) + "]"; + tmp += "\n"; + int ret =fwrite(tmp.c_str(),tmp.size(),1,this->mFile); + fflush(this->mFile); + return ret; + }else{ // 已经过天了 + this->mCurrentDate = getTimeDate(); + string path = getTimeDate() + ".log"; + this->mFile = fopen(path.c_str(),"w+"); + if (this->mFile == nullptr){ + this->error = true; + } + string tmp = getTime(); + tmp += ":"; + tmp += dat; + tmp += "at [" + function + " line " + std::to_string(line) + "]"; + tmp += "\n"; + int ret = fwrite(tmp.c_str(),tmp.size(),1,this->mFile); + fflush(this->mFile); + return ret; + } + return 0; +} + void _C_Loger::operator<<(const string& wb){ // 还没有过天 if(getTimeDate() == this->mCurrentDate){ @@ -38,7 +68,9 @@ void _C_Loger::operator<<(const string& wb){ this->error = true; } } + fprintf(this->mFile,wb.c_str(),wb.size()); } + bool file_existed(string path) { fstream _file; _file.open(path.c_str(),ios::in); @@ -56,6 +88,7 @@ _C_Loger::_C_Loger(FILE *p){ this->mFile = p; this->mCurrentDate = getTime(); } + _C_Loger::_C_Loger(string path) { this->mCurrentDate = getTimeDate(); this->mCurrentPath = path + this->mCurrentDate; @@ -64,6 +97,6 @@ _C_Loger::_C_Loger(string path) { fprintf(stderr,"error open log files %s code %d,please check file path",this->mCurrentPath.c_str(),errno); exit(0); }else{ - + } } \ No newline at end of file diff --git a/test/src/cpp11/CMakeLists.txt b/test/src/cpp11/CMakeLists.txt index 00fe11b..07592e7 100644 --- a/test/src/cpp11/CMakeLists.txt +++ b/test/src/cpp11/CMakeLists.txt @@ -7,7 +7,11 @@ message("current dir" ${CMAKE_CURRENT_SOURCE_DIR}) aux_source_directory(. SOURCE) message(info ${SOURCE}) link_directories("./third/jsoncpp/lib/") +link_directories("../../../obj/") + link_libraries(jsoncpp) +link_libraries(generallib) + add_executable(cpp11 ${SOURCE} ) include_directories("./third/jsoncpp/include/pkgsrc/include/json") include_directories("../../../obj/inc/") diff --git a/test/src/cpp11/cpp11_test.cpp b/test/src/cpp11/cpp11_test.cpp index e290946..0c2b507 100644 --- a/test/src/cpp11/cpp11_test.cpp +++ b/test/src/cpp11/cpp11_test.cpp @@ -8,11 +8,12 @@ using namespace std; #include "threadpool.h" #include "json.h" #include "template.h" - extern "C"{ #include #include } +#include "loger.h" + int main(){ // std::cout<<"test start"<