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
28
35class ILogger {
36 public:
37 virtual ~ILogger() = default;
38 virtual void AddLogMessage(
39 const LogMessage &message) = 0;
40 virtual void Stop();
41
51 void EnableSeverityLevel(LogSeverity severity, bool enable);
52
60 [[nodiscard]] bool IsSeverityLevelEnabled(LogSeverity severity) const;
61
69 void ShowLocation(bool show) { show_location_ = show; }
70
77 [[nodiscard]] bool ShowLocation() const { return show_location_; }
78
79 [[nodiscard]] virtual bool HasLogFile()
80 const;
81 [[nodiscard]] virtual std::string Filename()
82 const;
83 protected:
84 ILogger() = default;
85 private:
86 std::array<std::atomic<bool>, 9> severity_filter_ = {
87 true, true, true, true, true, true, true, true, true};
88 std::atomic<bool> show_location_ = true;
89};
90
91} // 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:77
void ShowLocation(bool show)
Enable or disable the source location information.
Definition ilogger.h:69
ILogger()=default
Constructor.
virtual void Stop()
Stops any worker thread.
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:26