Logger 日志类
线程安全的日志组件
默认保存到文件,并支持回调函数,比如显示到界面
#ifndef LOGGER_H
#define LOGGER_H
#include <iostream>
#include <sstream>
#include <mutex>
#include <thread>
#include <iomanip>
#include <fstream>
#include <string>
#include <condition_variable>
#include <thread>
#include <queue>
#include <chrono>
#include <ctime>
#include <functional>
// 线程安全的日志组件
class Logger
{
public:
enum class LogLevel
{
Unknown=0, //未知信息
Debug, //调试信息
Info, //普通信息
Trace, //详细信息
Warning, //警告信息
Error, //错误信息,但程序可以继续运行。
Fatal, //出现无法恢复的错误,可能导致程序崩溃。
Panic //出现严重错误,必须立即停止程序运行。
};
Logger();
Logger(const std::string& path);
~Logger();
void set_file_name(const std::string& path);
//添加回调函数
void set_callback(const std::function<void(std::pair<LogLevel, std::string>)>& func);
//输出日志
void add_log(LogLevel level, const std::string& message);
//转字符串
static std::string level2strin