aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/src/openmpt/logging/Logger.hpp
blob: af5f07419928586e8d6c6ace4c453a7169e39fde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */

#pragma once

#include "openmpt/all/BuildSettings.hpp"

#include "mpt/base/source_location.hpp"
#include "mpt/string/types.hpp"

OPENMPT_NAMESPACE_BEGIN

enum LogLevel
{
	LogDebug = 5,
	LogInformation = 4,
	LogNotification = 3,
	LogWarning = 2,
	LogError = 1
};

class ILogger
{
protected:
	virtual ~ILogger() = default;

public:
	virtual bool IsLevelActive(LogLevel level) const noexcept = 0;
	// facility: ASCII
	virtual bool IsFacilityActive(const char *facility) const noexcept = 0;
	// facility: ASCII
	virtual void SendLogMessage(const mpt::source_location &loc, LogLevel level, const char *facility, const mpt::ustring &text) const = 0;
};

#define MPT_LOG(logger, level, facility, text) \
	do \
	{ \
		if((logger).IsLevelActive((level))) \
		{ \
			if((logger).IsFacilityActive((facility))) \
			{ \
				(logger).SendLogMessage(MPT_SOURCE_LOCATION_CURRENT(), (level), (facility), (text)); \
			} \
		} \
	} while(0)

OPENMPT_NAMESPACE_END