moved to log_msg
This commit is contained in:
		@@ -75,7 +75,7 @@ inline void c11log::sinks::async_sink::_thread_loop()
 | 
			
		||||
            bufpair_t buf(msg.data(), msg.size());
 | 
			
		||||
            for (auto &sink : _sinks)
 | 
			
		||||
            {
 | 
			
		||||
                sink->log(buf, static_cast<level::level_enum>(_level.load()));
 | 
			
		||||
                sink->log(buf, level::INFO);
 | 
			
		||||
                if (!_active)
 | 
			
		||||
                    return;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -13,37 +13,39 @@ namespace sinks
 | 
			
		||||
class base_sink
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    base_sink() = default;
 | 
			
		||||
    base_sink(level::level_enum l):_level(l)
 | 
			
		||||
    {
 | 
			
		||||
    };
 | 
			
		||||
    base_sink(): _enabled(true) {}
 | 
			
		||||
    virtual ~base_sink() = default;
 | 
			
		||||
 | 
			
		||||
    base_sink(const base_sink&) = delete;
 | 
			
		||||
    base_sink& operator=(const base_sink&) = delete;
 | 
			
		||||
 | 
			
		||||
    void log(const bufpair_t &msg, level::level_enum level)
 | 
			
		||||
    void log(const log_msg& msg)
 | 
			
		||||
    {
 | 
			
		||||
        if (level >= _level)
 | 
			
		||||
        if (_enabled)
 | 
			
		||||
        {
 | 
			
		||||
            _sink_it(msg);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    void set_level(level::level_enum level)
 | 
			
		||||
    void enable(bool enabled)
 | 
			
		||||
    {
 | 
			
		||||
        _level = level;
 | 
			
		||||
        _enabled = enabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool is_enabled()
 | 
			
		||||
    {
 | 
			
		||||
        return _enabled.load();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void _sink_it(const bufpair_t& msg) = 0;
 | 
			
		||||
    std::atomic<int> _level {level::INFO};
 | 
			
		||||
    virtual void _sink_it(const log_msg& msg) = 0;
 | 
			
		||||
    std::atomic<bool> _enabled;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class null_sink:public base_sink
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    void _sink_it(const bufpair_t& ) override
 | 
			
		||||
    void _sink_it(const log_msg&) override
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -19,10 +19,10 @@ public:
 | 
			
		||||
    virtual ~console_sink() = default;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void _sink_it(const bufpair_t& msg) override
 | 
			
		||||
    virtual void _sink_it(const log_msg& msg) override
 | 
			
		||||
    {
 | 
			
		||||
        std::lock_guard<std::mutex> lock(_mutex);
 | 
			
		||||
        _ostream.write(msg.first, msg.second);
 | 
			
		||||
        _ostream.write(msg.msg_buf.first, msg.msg_buf.second);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::ostream& _ostream;
 | 
			
		||||
 
 | 
			
		||||
@@ -27,10 +27,10 @@ public:
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
protected:
 | 
			
		||||
    void _sink_it(const bufpair_t& msg) override
 | 
			
		||||
    void _sink_it(const log_msg& msg) override
 | 
			
		||||
    {
 | 
			
		||||
        std::lock_guard<std::mutex> lock(_mutex);
 | 
			
		||||
        _flush_helper.write(_ofstream, msg);
 | 
			
		||||
        _flush_helper.write(_ofstream, msg.msg_buf);
 | 
			
		||||
    }
 | 
			
		||||
private:
 | 
			
		||||
    std::mutex _mutex;
 | 
			
		||||
@@ -60,16 +60,17 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    void _sink_it(const bufpair_t& msg) override
 | 
			
		||||
    void _sink_it(const log_msg& msg) override
 | 
			
		||||
    {
 | 
			
		||||
        std::lock_guard<std::mutex> lock(_mutex);
 | 
			
		||||
        _current_size += msg.second;
 | 
			
		||||
 | 
			
		||||
        _current_size += msg.msg_buf.second;
 | 
			
		||||
        if (_current_size  > _max_size)
 | 
			
		||||
        {
 | 
			
		||||
            _rotate();
 | 
			
		||||
            _current_size = msg.second;
 | 
			
		||||
            _current_size = msg.msg_buf.second;
 | 
			
		||||
        }
 | 
			
		||||
        _flush_helper.write(_ofstream, msg);
 | 
			
		||||
        _flush_helper.write(_ofstream, msg.msg_buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -133,7 +134,7 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    void _sink_it(const bufpair_t& msg) override
 | 
			
		||||
    void _sink_it(const log_msg& msg) override
 | 
			
		||||
    {
 | 
			
		||||
        std::lock_guard<std::mutex> lock(_mutex);
 | 
			
		||||
        if (std::chrono::system_clock::now() >= _midnight_tp)
 | 
			
		||||
@@ -142,7 +143,7 @@ protected:
 | 
			
		||||
            _ofstream.open(_calc_filename(_base_filename, _extension));
 | 
			
		||||
            _midnight_tp = _calc_midnight_tp();
 | 
			
		||||
        }
 | 
			
		||||
        _flush_helper.write(_ofstream, msg);
 | 
			
		||||
        _flush_helper.write(_ofstream, msg.msg_buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user