userver: userver/logging/impl/logger_base.hpp Source File
Loading...
Searching...
No Matches
logger_base.hpp
1#pragma once
2
3#include <atomic>
4
5#include <userver/logging/format.hpp>
6#include <userver/logging/level.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace logging::impl {
11
12class TagWriter;
13
14/// Base logger class
15class LoggerBase {
16 public:
17 LoggerBase() = delete;
18 LoggerBase(const LoggerBase&) = delete;
19 LoggerBase(LoggerBase&&) = delete;
20 LoggerBase& operator=(const LoggerBase&) = delete;
21 LoggerBase& operator=(LoggerBase&&) = delete;
22
23 explicit LoggerBase(Format format) noexcept;
24
25 virtual ~LoggerBase();
26
27 virtual void Log(Level level, std::string_view msg) = 0;
28
29 virtual void Flush();
30
31 virtual void PrependCommonTags(TagWriter writer) const;
32
33 Format GetFormat() const noexcept;
34
35 virtual void SetLevel(Level level);
36 Level GetLevel() const noexcept;
37 bool ShouldLog(Level level) const noexcept;
38
39 void SetFlushOn(Level level);
40 bool ShouldFlush(Level level) const;
41
42 protected:
43 virtual bool DoShouldLog(Level level) const noexcept;
44
45 private:
46 const Format format_;
47 std::atomic<Level> level_{Level::kNone};
48 std::atomic<Level> flush_level_{Level::kWarning};
49};
50
51bool ShouldLogNoSpan(const LoggerBase& logger, Level level) noexcept;
52
53} // namespace logging::impl
54
55USERVER_NAMESPACE_END