UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
ilogger.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
8#pragma once
9#include <array>
10#include <atomic>
11#include <string>
12
13#include "logmessage.h"
14
15namespace util::log {
16
29
36class ILogger {
37 public:
38 virtual ~ILogger() = default;
39 virtual void AddLogMessage(
40 const LogMessage &message) = 0;
41 virtual void Stop();
42
52 void EnableSeverityLevel(LogSeverity severity, bool enable);
53
61 [[nodiscard]] bool IsSeverityLevelEnabled(LogSeverity severity) const;
62
70 void ShowLocation(bool show) { show_location_ = show; }
71
78 [[nodiscard]] bool ShowLocation() const { return show_location_; }
79
80 [[nodiscard]] virtual bool HasLogFile()
81 const;
82 [[nodiscard]] virtual std::string Filename()
83 const;
84 protected:
85 ILogger() = default;
86 private:
87 std::array<std::atomic<bool>, 9> severity_filter_ = {
88 true, true, true, true, true, true, true, true, true};
89 std::atomic<bool> show_location_ = true;
90};
91
92} // namespace util::log
void EnableSeverityLevel(LogSeverity severity, bool enable)
Enable or disable a severity.
virtual bool HasLogFile() const
Returns true if the logger has file.
virtual void AddLogMessage(const LogMessage &message)=0
Handle a log message.
virtual std::string Filename() const
Return full path to the log file.
virtual ~ILogger()=default
Destructor.
bool IsSeverityLevelEnabled(LogSeverity severity) const
Checks if a level is enabled or disabled.
bool ShowLocation() const
Returns true if the source location should be shown.
Definition ilogger.h:78
void ShowLocation(bool show)
Enable or disable the source location information.
Definition ilogger.h:70
ILogger()=default
Constructor.
virtual void Stop()
Stops any worker thread.
Definition logtolist.h:19
The log namespace is used for log related classes and functions.
Definition idirectory.h:18
LogSeverity
< Defines the log severity level
Definition logging.h:21
LogType
Definition ilogger.h:21
@ LogNothing
No logger.
Definition ilogger.h:22
@ LogToConsole
Log to the cout stream.
Definition ilogger.h:23
@ LogToSyslog
Logs to a syslog server.
Definition ilogger.h:26
@ LogToFile
Log to file.
Definition ilogger.h:24
@ LogToListen
Log to listen window (system messages).
Definition ilogger.h:25
Definition logmessage.h:27