source: trunk/GDE/SINA/builddir/include/spdlog/sinks/sink.h

Last change on this file was 19170, checked in by westram, 2 years ago
  • sina source
    • unpack + remove tarball
    • no longer ignore sina builddir.
File size: 1.4 KB
Line 
1//
2// Copyright(c) 2015 Gabi Melman.
3// Distributed under the MIT License (http://opensource.org/licenses/MIT)
4//
5
6#pragma once
7
8#include "spdlog/details/log_msg.h"
9#include "spdlog/details/pattern_formatter.h"
10#include "spdlog/formatter.h"
11
12namespace spdlog {
13namespace sinks {
14class sink
15{
16public:
17    sink()
18        : level_(level::trace)
19        , formatter_(new pattern_formatter())
20    {
21    }
22
23    explicit sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
24        : level_(level::trace)
25        , formatter_(std::move(formatter))
26    {
27    }
28
29    virtual ~sink() = default;
30    virtual void log(const details::log_msg &msg) = 0;
31    virtual void flush() = 0;
32    virtual void set_pattern(const std::string &pattern) = 0;
33    virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0;
34
35    bool should_log(level::level_enum msg_level) const
36    {
37        return msg_level >= level_.load(std::memory_order_relaxed);
38    }
39
40    void set_level(level::level_enum log_level)
41    {
42        level_.store(log_level);
43    }
44
45    level::level_enum level() const
46    {
47        return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
48    }
49
50protected:
51    // sink log level - default is all
52    level_t level_;
53
54    // sink formatter - default is full format
55    std::unique_ptr<spdlog::formatter> formatter_;
56};
57
58} // namespace sinks
59} // namespace spdlog
Note: See TracBrowser for help on using the repository browser.