Log: add "noexcept"
This commit is contained in:
parent
0a3a5a7c65
commit
377a2860cc
37
src/Log.cxx
37
src/Log.cxx
@ -30,7 +30,8 @@
|
|||||||
static constexpr Domain exception_domain("exception");
|
static constexpr Domain exception_domain("exception");
|
||||||
|
|
||||||
void
|
void
|
||||||
LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap)
|
LogFormatV(const Domain &domain, LogLevel level,
|
||||||
|
const char *fmt, va_list ap) noexcept
|
||||||
{
|
{
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
vsnprintf(msg, sizeof(msg), fmt, ap);
|
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||||
@ -38,7 +39,7 @@ LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
|
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -47,7 +48,7 @@ LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatDebug(const Domain &domain, const char *fmt, ...)
|
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -56,7 +57,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatInfo(const Domain &domain, const char *fmt, ...)
|
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -65,7 +66,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatDefault(const Domain &domain, const char *fmt, ...)
|
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -74,7 +75,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatWarning(const Domain &domain, const char *fmt, ...)
|
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -83,7 +84,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatError(const Domain &domain, const char *fmt, ...)
|
FormatError(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -92,7 +93,7 @@ FormatError(const Domain &domain, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception &e)
|
LogError(const std::exception &e) noexcept
|
||||||
{
|
{
|
||||||
Log(exception_domain, LogLevel::ERROR, e.what());
|
Log(exception_domain, LogLevel::ERROR, e.what());
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ LogError(const std::exception &e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception &e, const char *msg)
|
LogError(const std::exception &e, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
FormatError(exception_domain, "%s: %s", msg, e.what());
|
FormatError(exception_domain, "%s: %s", msg, e.what());
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ LogError(const std::exception &e, const char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatError(const std::exception &e, const char *fmt, ...)
|
FormatError(const std::exception &e, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -134,7 +135,7 @@ FormatError(const std::exception &e, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception_ptr &ep)
|
LogError(const std::exception_ptr &ep) noexcept
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::rethrow_exception(ep);
|
std::rethrow_exception(ep);
|
||||||
@ -147,7 +148,7 @@ LogError(const std::exception_ptr &ep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception_ptr &ep, const char *msg)
|
LogError(const std::exception_ptr &ep, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::rethrow_exception(ep);
|
std::rethrow_exception(ep);
|
||||||
@ -160,7 +161,7 @@ LogError(const std::exception_ptr &ep, const char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatError(const std::exception_ptr &ep, const char *fmt, ...)
|
FormatError(const std::exception_ptr &ep, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -172,19 +173,19 @@ FormatError(const std::exception_ptr &ep, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogErrno(const Domain &domain, int e, const char *msg)
|
LogErrno(const Domain &domain, int e, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
LogFormat(domain, LogLevel::ERROR, "%s: %s", msg, strerror(e));
|
LogFormat(domain, LogLevel::ERROR, "%s: %s", msg, strerror(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogErrno(const Domain &domain, const char *msg)
|
LogErrno(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
LogErrno(domain, errno, msg);
|
LogErrno(domain, errno, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap)
|
FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap) noexcept
|
||||||
{
|
{
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
vsnprintf(msg, sizeof(msg), fmt, ap);
|
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||||
@ -193,7 +194,7 @@ FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatErrno(const Domain &domain, int e, const char *fmt, ...)
|
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@ -202,7 +203,7 @@ FormatErrno(const Domain &domain, int e, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FormatErrno(const Domain &domain, const char *fmt, ...)
|
FormatErrno(const Domain &domain, const char *fmt, ...) noexcept
|
||||||
{
|
{
|
||||||
const int e = errno;
|
const int e = errno;
|
||||||
|
|
||||||
|
44
src/Log.hxx
44
src/Log.hxx
@ -28,94 +28,94 @@
|
|||||||
class Domain;
|
class Domain;
|
||||||
|
|
||||||
void
|
void
|
||||||
Log(const Domain &domain, LogLevel level, const char *msg);
|
Log(const Domain &domain, LogLevel level, const char *msg) noexcept;
|
||||||
|
|
||||||
gcc_printf(3,4)
|
gcc_printf(3,4)
|
||||||
void
|
void
|
||||||
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...);
|
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
LogDebug(const Domain &domain, const char *msg)
|
LogDebug(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
Log(domain, LogLevel::DEBUG, msg);
|
Log(domain, LogLevel::DEBUG, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatDebug(const Domain &domain, const char *fmt, ...);
|
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
LogInfo(const Domain &domain, const char *msg)
|
LogInfo(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
Log(domain, LogLevel::INFO, msg);
|
Log(domain, LogLevel::INFO, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatInfo(const Domain &domain, const char *fmt, ...);
|
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
LogDefault(const Domain &domain, const char *msg)
|
LogDefault(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
Log(domain, LogLevel::DEFAULT, msg);
|
Log(domain, LogLevel::DEFAULT, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatDefault(const Domain &domain, const char *fmt, ...);
|
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
LogWarning(const Domain &domain, const char *msg)
|
LogWarning(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
Log(domain, LogLevel::WARNING, msg);
|
Log(domain, LogLevel::WARNING, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatWarning(const Domain &domain, const char *fmt, ...);
|
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
LogError(const Domain &domain, const char *msg)
|
LogError(const Domain &domain, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
Log(domain, LogLevel::ERROR, msg);
|
Log(domain, LogLevel::ERROR, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception &e);
|
LogError(const std::exception &e) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception &e, const char *msg);
|
LogError(const std::exception &e, const char *msg) noexcept;
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatError(const std::exception &e, const char *fmt, ...);
|
FormatError(const std::exception &e, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception_ptr &ep);
|
LogError(const std::exception_ptr &ep) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogError(const std::exception_ptr &ep, const char *msg);
|
LogError(const std::exception_ptr &ep, const char *msg) noexcept;
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatError(const std::exception_ptr &ep, const char *fmt, ...);
|
FormatError(const std::exception_ptr &ep, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatError(const Domain &domain, const char *fmt, ...);
|
FormatError(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogErrno(const Domain &domain, int e, const char *msg);
|
LogErrno(const Domain &domain, int e, const char *msg) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogErrno(const Domain &domain, const char *msg);
|
LogErrno(const Domain &domain, const char *msg) noexcept;
|
||||||
|
|
||||||
gcc_printf(3,4)
|
gcc_printf(3,4)
|
||||||
void
|
void
|
||||||
FormatErrno(const Domain &domain, int e, const char *fmt, ...);
|
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
gcc_printf(2,3)
|
gcc_printf(2,3)
|
||||||
void
|
void
|
||||||
FormatErrno(const Domain &domain, const char *fmt, ...);
|
FormatErrno(const Domain &domain, const char *fmt, ...) noexcept;
|
||||||
|
|
||||||
#endif /* LOG_H */
|
#endif /* LOG_H */
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ToAndroidLogLevel(LogLevel log_level)
|
ToAndroidLogLevel(LogLevel log_level) noexcept
|
||||||
{
|
{
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case LogLevel::DEBUG:
|
case LogLevel::DEBUG:
|
||||||
@ -68,13 +68,13 @@ static bool enable_syslog;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
SetLogThreshold(LogLevel _threshold)
|
SetLogThreshold(LogLevel _threshold) noexcept
|
||||||
{
|
{
|
||||||
log_threshold = _threshold;
|
log_threshold = _threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EnableLogTimestamp()
|
EnableLogTimestamp() noexcept
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYSLOG
|
#ifdef HAVE_SYSLOG
|
||||||
assert(!enable_syslog);
|
assert(!enable_syslog);
|
||||||
@ -84,7 +84,8 @@ EnableLogTimestamp()
|
|||||||
enable_timestamp = true;
|
enable_timestamp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *log_date(void)
|
static const char *
|
||||||
|
log_date() noexcept
|
||||||
{
|
{
|
||||||
static constexpr size_t LOG_DATE_BUF_SIZE = 16;
|
static constexpr size_t LOG_DATE_BUF_SIZE = 16;
|
||||||
static char buf[LOG_DATE_BUF_SIZE];
|
static char buf[LOG_DATE_BUF_SIZE];
|
||||||
@ -98,7 +99,7 @@ static const char *log_date(void)
|
|||||||
* characters.
|
* characters.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
chomp_length(const char *p)
|
chomp_length(const char *p) noexcept
|
||||||
{
|
{
|
||||||
size_t length = strlen(p);
|
size_t length = strlen(p);
|
||||||
return StripRight(p, length);
|
return StripRight(p, length);
|
||||||
@ -106,8 +107,9 @@ chomp_length(const char *p)
|
|||||||
|
|
||||||
#ifdef HAVE_SYSLOG
|
#ifdef HAVE_SYSLOG
|
||||||
|
|
||||||
|
gcc_const
|
||||||
static int
|
static int
|
||||||
ToSysLogLevel(LogLevel log_level)
|
ToSysLogLevel(LogLevel log_level) noexcept
|
||||||
{
|
{
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case LogLevel::DEBUG:
|
case LogLevel::DEBUG:
|
||||||
@ -131,7 +133,7 @@ ToSysLogLevel(LogLevel log_level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SysLog(const Domain &domain, LogLevel log_level, const char *message)
|
SysLog(const Domain &domain, LogLevel log_level, const char *message) noexcept
|
||||||
{
|
{
|
||||||
syslog(ToSysLogLevel(log_level), "%s: %.*s",
|
syslog(ToSysLogLevel(log_level), "%s: %.*s",
|
||||||
domain.GetName(),
|
domain.GetName(),
|
||||||
@ -139,14 +141,14 @@ SysLog(const Domain &domain, LogLevel log_level, const char *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogInitSysLog()
|
LogInitSysLog() noexcept
|
||||||
{
|
{
|
||||||
openlog(PACKAGE, 0, LOG_DAEMON);
|
openlog(PACKAGE, 0, LOG_DAEMON);
|
||||||
enable_syslog = true;
|
enable_syslog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LogFinishSysLog()
|
LogFinishSysLog() noexcept
|
||||||
{
|
{
|
||||||
if (enable_syslog)
|
if (enable_syslog)
|
||||||
closelog();
|
closelog();
|
||||||
@ -155,7 +157,7 @@ LogFinishSysLog()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
FileLog(const Domain &domain, const char *message)
|
FileLog(const Domain &domain, const char *message) noexcept
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s%s: %.*s\n",
|
fprintf(stderr, "%s%s: %.*s\n",
|
||||||
enable_timestamp ? log_date() : "",
|
enable_timestamp ? log_date() : "",
|
||||||
@ -172,7 +174,7 @@ FileLog(const Domain &domain, const char *message)
|
|||||||
#endif /* !ANDROID */
|
#endif /* !ANDROID */
|
||||||
|
|
||||||
void
|
void
|
||||||
Log(const Domain &domain, LogLevel level, const char *msg)
|
Log(const Domain &domain, LogLevel level, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
__android_log_print(ToAndroidLogLevel(level), "MPD",
|
__android_log_print(ToAndroidLogLevel(level), "MPD",
|
||||||
|
@ -24,15 +24,15 @@
|
|||||||
#include "LogLevel.hxx"
|
#include "LogLevel.hxx"
|
||||||
|
|
||||||
void
|
void
|
||||||
SetLogThreshold(LogLevel _threshold);
|
SetLogThreshold(LogLevel _threshold) noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
EnableLogTimestamp();
|
EnableLogTimestamp() noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogInitSysLog();
|
LogInitSysLog() noexcept;
|
||||||
|
|
||||||
void
|
void
|
||||||
LogFinishSysLog();
|
LogFinishSysLog() noexcept;
|
||||||
|
|
||||||
#endif /* LOG_H */
|
#endif /* LOG_H */
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap);
|
LogFormatV(const Domain &domain, LogLevel level,
|
||||||
|
const char *fmt, va_list ap) noexcept;
|
||||||
|
|
||||||
#endif /* LOG_H */
|
#endif /* LOG_H */
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
Log(const Domain &domain, gcc_unused LogLevel level, const char *msg)
|
Log(const Domain &domain, gcc_unused LogLevel level, const char *msg) noexcept
|
||||||
{
|
{
|
||||||
fprintf(stderr, "[%s] %s\n", domain.GetName(), msg);
|
fprintf(stderr, "[%s] %s\n", domain.GetName(), msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user