Log: add "noexcept"

This commit is contained in:
Max Kellermann 2017-05-16 07:00:53 +02:00
parent 0a3a5a7c65
commit 377a2860cc
6 changed files with 61 additions and 57 deletions

View File

@ -30,7 +30,8 @@
static constexpr Domain exception_domain("exception");
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];
vsnprintf(msg, sizeof(msg), fmt, ap);
@ -38,7 +39,7 @@ LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap)
}
void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -47,7 +48,7 @@ LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
}
void
FormatDebug(const Domain &domain, const char *fmt, ...)
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -56,7 +57,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...)
}
void
FormatInfo(const Domain &domain, const char *fmt, ...)
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -65,7 +66,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...)
}
void
FormatDefault(const Domain &domain, const char *fmt, ...)
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -74,7 +75,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...)
}
void
FormatWarning(const Domain &domain, const char *fmt, ...)
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -83,7 +84,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...)
}
void
FormatError(const Domain &domain, const char *fmt, ...)
FormatError(const Domain &domain, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -92,7 +93,7 @@ FormatError(const Domain &domain, const char *fmt, ...)
}
void
LogError(const std::exception &e)
LogError(const std::exception &e) noexcept
{
Log(exception_domain, LogLevel::ERROR, e.what());
@ -107,7 +108,7 @@ LogError(const std::exception &e)
}
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());
@ -122,7 +123,7 @@ LogError(const std::exception &e, const char *msg)
}
void
FormatError(const std::exception &e, const char *fmt, ...)
FormatError(const std::exception &e, const char *fmt, ...) noexcept
{
char msg[1024];
va_list ap;
@ -134,7 +135,7 @@ FormatError(const std::exception &e, const char *fmt, ...)
}
void
LogError(const std::exception_ptr &ep)
LogError(const std::exception_ptr &ep) noexcept
{
try {
std::rethrow_exception(ep);
@ -147,7 +148,7 @@ LogError(const std::exception_ptr &ep)
}
void
LogError(const std::exception_ptr &ep, const char *msg)
LogError(const std::exception_ptr &ep, const char *msg) noexcept
{
try {
std::rethrow_exception(ep);
@ -160,7 +161,7 @@ LogError(const std::exception_ptr &ep, const char *msg)
}
void
FormatError(const std::exception_ptr &ep, const char *fmt, ...)
FormatError(const std::exception_ptr &ep, const char *fmt, ...) noexcept
{
char msg[1024];
va_list ap;
@ -172,19 +173,19 @@ FormatError(const std::exception_ptr &ep, const char *fmt, ...)
}
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));
}
void
LogErrno(const Domain &domain, const char *msg)
LogErrno(const Domain &domain, const char *msg) noexcept
{
LogErrno(domain, errno, msg);
}
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];
vsnprintf(msg, sizeof(msg), fmt, ap);
@ -193,7 +194,7 @@ FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap)
}
void
FormatErrno(const Domain &domain, int e, const char *fmt, ...)
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept
{
va_list ap;
va_start(ap, fmt);
@ -202,7 +203,7 @@ FormatErrno(const Domain &domain, int e, const char *fmt, ...)
}
void
FormatErrno(const Domain &domain, const char *fmt, ...)
FormatErrno(const Domain &domain, const char *fmt, ...) noexcept
{
const int e = errno;

View File

@ -28,94 +28,94 @@
class Domain;
void
Log(const Domain &domain, LogLevel level, const char *msg);
Log(const Domain &domain, LogLevel level, const char *msg) noexcept;
gcc_printf(3,4)
void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...);
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept;
static inline void
LogDebug(const Domain &domain, const char *msg)
LogDebug(const Domain &domain, const char *msg) noexcept
{
Log(domain, LogLevel::DEBUG, msg);
}
gcc_printf(2,3)
void
FormatDebug(const Domain &domain, const char *fmt, ...);
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept;
static inline void
LogInfo(const Domain &domain, const char *msg)
LogInfo(const Domain &domain, const char *msg) noexcept
{
Log(domain, LogLevel::INFO, msg);
}
gcc_printf(2,3)
void
FormatInfo(const Domain &domain, const char *fmt, ...);
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept;
static inline void
LogDefault(const Domain &domain, const char *msg)
LogDefault(const Domain &domain, const char *msg) noexcept
{
Log(domain, LogLevel::DEFAULT, msg);
}
gcc_printf(2,3)
void
FormatDefault(const Domain &domain, const char *fmt, ...);
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept;
static inline void
LogWarning(const Domain &domain, const char *msg)
LogWarning(const Domain &domain, const char *msg) noexcept
{
Log(domain, LogLevel::WARNING, msg);
}
gcc_printf(2,3)
void
FormatWarning(const Domain &domain, const char *fmt, ...);
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept;
static inline void
LogError(const Domain &domain, const char *msg)
LogError(const Domain &domain, const char *msg) noexcept
{
Log(domain, LogLevel::ERROR, msg);
}
void
LogError(const std::exception &e);
LogError(const std::exception &e) noexcept;
void
LogError(const std::exception &e, const char *msg);
LogError(const std::exception &e, const char *msg) noexcept;
gcc_printf(2,3)
void
FormatError(const std::exception &e, const char *fmt, ...);
FormatError(const std::exception &e, const char *fmt, ...) noexcept;
void
LogError(const std::exception_ptr &ep);
LogError(const std::exception_ptr &ep) noexcept;
void
LogError(const std::exception_ptr &ep, const char *msg);
LogError(const std::exception_ptr &ep, const char *msg) noexcept;
gcc_printf(2,3)
void
FormatError(const std::exception_ptr &ep, const char *fmt, ...);
FormatError(const std::exception_ptr &ep, const char *fmt, ...) noexcept;
gcc_printf(2,3)
void
FormatError(const Domain &domain, const char *fmt, ...);
FormatError(const Domain &domain, const char *fmt, ...) noexcept;
void
LogErrno(const Domain &domain, int e, const char *msg);
LogErrno(const Domain &domain, int e, const char *msg) noexcept;
void
LogErrno(const Domain &domain, const char *msg);
LogErrno(const Domain &domain, const char *msg) noexcept;
gcc_printf(3,4)
void
FormatErrno(const Domain &domain, int e, const char *fmt, ...);
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept;
gcc_printf(2,3)
void
FormatErrno(const Domain &domain, const char *fmt, ...);
FormatErrno(const Domain &domain, const char *fmt, ...) noexcept;
#endif /* LOG_H */

View File

@ -36,7 +36,7 @@
#include <android/log.h>
static int
ToAndroidLogLevel(LogLevel log_level)
ToAndroidLogLevel(LogLevel log_level) noexcept
{
switch (log_level) {
case LogLevel::DEBUG:
@ -68,13 +68,13 @@ static bool enable_syslog;
#endif
void
SetLogThreshold(LogLevel _threshold)
SetLogThreshold(LogLevel _threshold) noexcept
{
log_threshold = _threshold;
}
void
EnableLogTimestamp()
EnableLogTimestamp() noexcept
{
#ifdef HAVE_SYSLOG
assert(!enable_syslog);
@ -84,7 +84,8 @@ EnableLogTimestamp()
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 char buf[LOG_DATE_BUF_SIZE];
@ -98,7 +99,7 @@ static const char *log_date(void)
* characters.
*/
static int
chomp_length(const char *p)
chomp_length(const char *p) noexcept
{
size_t length = strlen(p);
return StripRight(p, length);
@ -106,8 +107,9 @@ chomp_length(const char *p)
#ifdef HAVE_SYSLOG
gcc_const
static int
ToSysLogLevel(LogLevel log_level)
ToSysLogLevel(LogLevel log_level) noexcept
{
switch (log_level) {
case LogLevel::DEBUG:
@ -131,7 +133,7 @@ ToSysLogLevel(LogLevel log_level)
}
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",
domain.GetName(),
@ -139,14 +141,14 @@ SysLog(const Domain &domain, LogLevel log_level, const char *message)
}
void
LogInitSysLog()
LogInitSysLog() noexcept
{
openlog(PACKAGE, 0, LOG_DAEMON);
enable_syslog = true;
}
void
LogFinishSysLog()
LogFinishSysLog() noexcept
{
if (enable_syslog)
closelog();
@ -155,7 +157,7 @@ LogFinishSysLog()
#endif
static void
FileLog(const Domain &domain, const char *message)
FileLog(const Domain &domain, const char *message) noexcept
{
fprintf(stderr, "%s%s: %.*s\n",
enable_timestamp ? log_date() : "",
@ -172,7 +174,7 @@ FileLog(const Domain &domain, const char *message)
#endif /* !ANDROID */
void
Log(const Domain &domain, LogLevel level, const char *msg)
Log(const Domain &domain, LogLevel level, const char *msg) noexcept
{
#ifdef ANDROID
__android_log_print(ToAndroidLogLevel(level), "MPD",

View File

@ -24,15 +24,15 @@
#include "LogLevel.hxx"
void
SetLogThreshold(LogLevel _threshold);
SetLogThreshold(LogLevel _threshold) noexcept;
void
EnableLogTimestamp();
EnableLogTimestamp() noexcept;
void
LogInitSysLog();
LogInitSysLog() noexcept;
void
LogFinishSysLog();
LogFinishSysLog() noexcept;
#endif /* LOG_H */

View File

@ -25,6 +25,7 @@
#include <stdarg.h>
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 */

View File

@ -26,7 +26,7 @@
#include <stdio.h>
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);
}