c++ 自定义Logger 日志类

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值