Debian Codegraph @

src/openmpt/logging/Logger.hpp

raw
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */
3
4 #pragma once
5
6 #include "openmpt/all/BuildSettings.hpp"
7
8 #include "mpt/base/source_location.hpp"
9 #include "mpt/string/types.hpp"
10
11 OPENMPT_NAMESPACE_BEGIN
12
13 enum LogLevel
14 {
15 LogDebug = 5,
16 LogInformation = 4,
17 LogNotification = 3,
18 LogWarning = 2,
19 LogError = 1
20 };
21
22 class ILogger
23 {
24 protected:
25 virtual ~ILogger() = default;
26
27 public:
28 virtual bool IsLevelActive(LogLevel level) const noexcept = 0;
29 // facility: ASCII
30 virtual bool IsFacilityActive(const char *facility) const noexcept = 0;
31 // facility: ASCII
32 virtual void SendLogMessage(const mpt::source_location &loc, LogLevel level, const char *facility, const mpt::ustring &text) const = 0;
33 };
34
35 #define MPT_LOG(logger, level, facility, text) \
36 do \
37 { \
38 if((logger).IsLevelActive((level))) \
39 { \
40 if((logger).IsFacilityActive((facility))) \
41 { \
42 (logger).SendLogMessage(MPT_SOURCE_LOCATION_CURRENT(), (level), (facility), (text)); \
43 } \
44 } \
45 } while(0)
46
47 OPENMPT_NAMESPACE_END