no message
parent
bf3911d4df
commit
8ac3df8244
|
@ -28,7 +28,7 @@ public:
|
||||||
Loger(string path,string prefix);
|
Loger(string path,string prefix);
|
||||||
Loger(string path,string prefix,bool old);
|
Loger(string path,string prefix,bool old);
|
||||||
~Loger();
|
~Loger();
|
||||||
#define DEBUG_FILE_POSITION __FILE__,__LINE__
|
#define FILE_POSITION __FILE__,__LINE__
|
||||||
void SetMinimalLevel(Level);
|
void SetMinimalLevel(Level);
|
||||||
void SetWorkMode(Mode);
|
void SetWorkMode(Mode);
|
||||||
int Debug(string,string file = __FILE__,int line = __LINE__);
|
int Debug(string,string file = __FILE__,int line = __LINE__);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
// 一个异步线程的封装
|
||||||
|
template<class Function,class Ret,class ... Args>
|
||||||
|
class ASyncProcess {
|
||||||
|
public:
|
||||||
|
ASyncProcess(Function t,Ret &ret,Args... args){
|
||||||
|
std::cout<<"ASyncProcess construct"<<std::endl;
|
||||||
|
mThread = new std::thread([this,t,&ret,args...](){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = t(args...);
|
||||||
|
this->m_finish = true;
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << '\n';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ASyncProcess(Function t,Ret &ret){
|
||||||
|
std::cout<<"ASyncProcess construct"<<std::endl;
|
||||||
|
mThread = new std::thread([this,t,&ret](){
|
||||||
|
ret = t();
|
||||||
|
mMutex.lock();
|
||||||
|
this->m_finish = true;
|
||||||
|
mMutex.unlock();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
bool Finish(){
|
||||||
|
return m_finish;
|
||||||
|
}
|
||||||
|
virtual ~ASyncProcess() {
|
||||||
|
mThread->detach();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
bool m_finish = false;
|
||||||
|
std::thread *mThread;
|
||||||
|
std::mutex mMutex;
|
||||||
|
};
|
|
@ -39,7 +39,7 @@ int Loger::Debug(string dat,string function,int line) {
|
||||||
}
|
}
|
||||||
// 还没有过天
|
// 还没有过天
|
||||||
if(getTimeDate() == this->mCurrentDate){
|
if(getTimeDate() == this->mCurrentDate){
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[DEBUG] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
@ -57,7 +57,7 @@ int Loger::Debug(string dat,string function,int line) {
|
||||||
std::cout<<"error Loger open file\r\n"<<std::endl;
|
std::cout<<"error Loger open file\r\n"<<std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[DEBUG] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
@ -133,7 +133,7 @@ int Loger::Warning(string dat,string function,int line) {
|
||||||
}
|
}
|
||||||
// 还没有过天
|
// 还没有过天
|
||||||
if(getTimeDate() == this->mCurrentDate){
|
if(getTimeDate() == this->mCurrentDate){
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[WARNING] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
@ -151,7 +151,7 @@ int Loger::Warning(string dat,string function,int line) {
|
||||||
std::cout<<"error Loger open file\r\n"<<std::endl;
|
std::cout<<"error Loger open file\r\n"<<std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[WARNING] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
@ -164,7 +164,6 @@ int Loger::Warning(string dat,string function,int line) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Loger::Info(string dat,string function,int line) {
|
int Loger::Info(string dat,string function,int line) {
|
||||||
if(mLevel > LEVEL_WARNING){
|
if(mLevel > LEVEL_WARNING){
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -182,7 +181,7 @@ int Loger::Info(string dat,string function,int line) {
|
||||||
}
|
}
|
||||||
// 还没有过天
|
// 还没有过天
|
||||||
if(getTimeDate() == this->mCurrentDate){
|
if(getTimeDate() == this->mCurrentDate){
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[INFO] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
@ -200,7 +199,7 @@ int Loger::Info(string dat,string function,int line) {
|
||||||
std::cout<<"error Loger open file\r\n"<<std::endl;
|
std::cout<<"error Loger open file\r\n"<<std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
string tmp = "[" + this->mPrefix + "] ";
|
string tmp = "[INFO] ";
|
||||||
tmp += getTime();
|
tmp += getTime();
|
||||||
tmp += ": ";
|
tmp += ": ";
|
||||||
tmp += dat;
|
tmp += dat;
|
||||||
|
|
Loading…
Reference in New Issue