первый
This commit is contained in:
54
lib/logger.h
Normal file
54
lib/logger.h
Normal file
@ -0,0 +1,54 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#ifndef logRotateH
|
||||
#define logRotateH
|
||||
//---------------------------------------------------------------------------
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <sys/time.h>
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
//---------------------------------------------------------------------------
|
||||
struct LogRec{
|
||||
std::string thread;
|
||||
std::string level;
|
||||
std::string data;
|
||||
bool cout;
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
class Logger {
|
||||
private:
|
||||
|
||||
std::ofstream file;
|
||||
std::string fileName;
|
||||
std::string date;
|
||||
|
||||
std::atomic<bool> stop;
|
||||
|
||||
std::mutex queueMutex;
|
||||
|
||||
std::queue<LogRec> logQueue;
|
||||
std::condition_variable queueCondition;
|
||||
std::thread logThread;
|
||||
|
||||
void processQueue();
|
||||
void writeLog(std::string thread, std::string level, std::string data, bool cout);
|
||||
void rotateLogFile();
|
||||
|
||||
void openLogFile();
|
||||
std::string getCurrentDate();
|
||||
std::string getCurrentDateTime();
|
||||
public:
|
||||
Logger(std::string fileName);
|
||||
~Logger();
|
||||
void log(std::string thread, std::string level, std::string data, bool cout=false);
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
Reference in New Issue
Block a user