Log.hxx 3.7 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20 21
#ifndef MPD_LOG_HXX
#define MPD_LOG_HXX
Warren Dukes's avatar
Warren Dukes committed
22

23
#include "LogLevel.hxx"
24
#include "util/Compiler.h"
25

26
#include <exception>
27

28 29 30
class Domain;

void
31
Log(LogLevel level, const Domain &domain, const char *msg) noexcept;
32

Max Kellermann's avatar
Max Kellermann committed
33
gcc_printf(3,4)
34
void
35
LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept;
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
void
Log(LogLevel level, const std::exception &e) noexcept;

void
Log(LogLevel level, const std::exception &e, const char *msg) noexcept;

gcc_printf(3,4)
void
LogFormat(LogLevel level, const std::exception &e,
	  const char *fmt, ...) noexcept;

void
Log(LogLevel level, const std::exception_ptr &ep) noexcept;

void
Log(LogLevel level, const std::exception_ptr &ep, const char *msg) noexcept;

gcc_printf(3,4)
void
LogFormat(LogLevel level, const std::exception_ptr &ep,
	  const char *fmt, ...) noexcept;

59
static inline void
Max Kellermann's avatar
Max Kellermann committed
60
LogDebug(const Domain &domain, const char *msg) noexcept
61
{
62
	Log(LogLevel::DEBUG, domain, msg);
63 64
}

Max Kellermann's avatar
Max Kellermann committed
65
gcc_printf(2,3)
66
void
Max Kellermann's avatar
Max Kellermann committed
67
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept;
68 69

static inline void
Max Kellermann's avatar
Max Kellermann committed
70
LogInfo(const Domain &domain, const char *msg) noexcept
71
{
72
	Log(LogLevel::INFO, domain, msg);
73 74
}

Max Kellermann's avatar
Max Kellermann committed
75
gcc_printf(2,3)
76
void
Max Kellermann's avatar
Max Kellermann committed
77
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept;
78

79
static inline void
Max Kellermann's avatar
Max Kellermann committed
80
LogDefault(const Domain &domain, const char *msg) noexcept
81
{
82
	Log(LogLevel::DEFAULT, domain, msg);
83 84 85 86
}

gcc_printf(2,3)
void
Max Kellermann's avatar
Max Kellermann committed
87
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept;
88

89
static inline void
Max Kellermann's avatar
Max Kellermann committed
90
LogWarning(const Domain &domain, const char *msg) noexcept
91
{
92
	Log(LogLevel::WARNING, domain, msg);
93 94
}

Max Kellermann's avatar
Max Kellermann committed
95
gcc_printf(2,3)
96
void
Max Kellermann's avatar
Max Kellermann committed
97
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept;
98 99

static inline void
Max Kellermann's avatar
Max Kellermann committed
100
LogError(const Domain &domain, const char *msg) noexcept
101
{
102
	Log(LogLevel::ERROR, domain, msg);
103 104
}

105 106 107 108 109
inline void
LogError(const std::exception &e) noexcept
{
	Log(LogLevel::ERROR, e);
}
110

111 112 113 114 115
inline void
LogError(const std::exception &e, const char *msg) noexcept
{
	Log(LogLevel::ERROR, e, msg);
}
116

117 118 119 120 121 122
template<typename... Args>
inline void
FormatError(const std::exception &e, const char *fmt, Args&&... args) noexcept
{
	LogFormat(LogLevel::ERROR, e, fmt, std::forward<Args>(args)...);
}
123

124 125 126 127 128
inline void
LogError(const std::exception_ptr &ep) noexcept
{
	Log(LogLevel::ERROR, ep);
}
129

130 131 132 133 134
inline void
LogError(const std::exception_ptr &ep, const char *msg) noexcept
{
	Log(LogLevel::ERROR, ep, msg);
}
135

136 137 138 139 140 141 142
template<typename... Args>
inline void
FormatError(const std::exception_ptr &ep,
	    const char *fmt, Args&&... args) noexcept
{
	LogFormat(LogLevel::ERROR, ep, fmt, std::forward<Args>(args)...);
}
143

Max Kellermann's avatar
Max Kellermann committed
144
gcc_printf(2,3)
145
void
Max Kellermann's avatar
Max Kellermann committed
146
FormatError(const Domain &domain, const char *fmt, ...) noexcept;
147

148
void
Max Kellermann's avatar
Max Kellermann committed
149
LogErrno(const Domain &domain, int e, const char *msg) noexcept;
150

151
void
Max Kellermann's avatar
Max Kellermann committed
152
LogErrno(const Domain &domain, const char *msg) noexcept;
Warren Dukes's avatar
Warren Dukes committed
153

Max Kellermann's avatar
Max Kellermann committed
154
gcc_printf(3,4)
155
void
Max Kellermann's avatar
Max Kellermann committed
156
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept;
157

Max Kellermann's avatar
Max Kellermann committed
158
gcc_printf(2,3)
159
void
Max Kellermann's avatar
Max Kellermann committed
160
FormatErrno(const Domain &domain, const char *fmt, ...) noexcept;
Warren Dukes's avatar
Warren Dukes committed
161

Eric Wong's avatar
Eric Wong committed
162
#endif /* LOG_H */