Log: make LogLevel the first parameter

Prepare for templated functions.
This commit is contained in:
Max Kellermann 2019-05-22 18:38:25 +02:00
parent e5f23678ca
commit 36e6079c57
9 changed files with 29 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -28,20 +28,20 @@
static constexpr Domain exception_domain("exception"); static constexpr Domain exception_domain("exception");
void void
LogFormatV(const Domain &domain, LogLevel level, LogFormatV(LogLevel level, const Domain &domain,
const char *fmt, va_list ap) noexcept 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);
Log(domain, level, msg); Log(level, domain, msg);
} }
void void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, level, fmt, ap); LogFormatV(level, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -50,7 +50,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, LogLevel::DEBUG, fmt, ap); LogFormatV(LogLevel::DEBUG, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -59,7 +59,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, LogLevel::INFO, fmt, ap); LogFormatV(LogLevel::INFO, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -68,7 +68,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, LogLevel::DEFAULT, fmt, ap); LogFormatV(LogLevel::DEFAULT, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -77,7 +77,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, LogLevel::WARNING, fmt, ap); LogFormatV(LogLevel::WARNING, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -86,7 +86,7 @@ FormatError(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(domain, LogLevel::ERROR, fmt, ap); LogFormatV(LogLevel::ERROR, domain, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -142,7 +142,7 @@ FormatError(const std::exception_ptr &ep, const char *fmt, ...) noexcept
void void
LogErrno(const Domain &domain, int e, const char *msg) noexcept LogErrno(const Domain &domain, int e, const char *msg) noexcept
{ {
LogFormat(domain, LogLevel::ERROR, "%s: %s", msg, strerror(e)); LogFormat(LogLevel::ERROR, domain, "%s: %s", msg, strerror(e));
} }
void void

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -28,16 +28,16 @@
class Domain; class Domain;
void void
Log(const Domain &domain, LogLevel level, const char *msg) noexcept; Log(LogLevel level, const Domain &domain, const char *msg) noexcept;
gcc_printf(3,4) gcc_printf(3,4)
void void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...) noexcept; LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept;
static inline void static inline void
LogDebug(const Domain &domain, const char *msg) noexcept LogDebug(const Domain &domain, const char *msg) noexcept
{ {
Log(domain, LogLevel::DEBUG, msg); Log(LogLevel::DEBUG, domain, msg);
} }
gcc_printf(2,3) gcc_printf(2,3)
@ -47,7 +47,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...) noexcept;
static inline void static inline void
LogInfo(const Domain &domain, const char *msg) noexcept LogInfo(const Domain &domain, const char *msg) noexcept
{ {
Log(domain, LogLevel::INFO, msg); Log(LogLevel::INFO, domain, msg);
} }
gcc_printf(2,3) gcc_printf(2,3)
@ -57,7 +57,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...) noexcept;
static inline void static inline void
LogDefault(const Domain &domain, const char *msg) noexcept LogDefault(const Domain &domain, const char *msg) noexcept
{ {
Log(domain, LogLevel::DEFAULT, msg); Log(LogLevel::DEFAULT, domain, msg);
} }
gcc_printf(2,3) gcc_printf(2,3)
@ -67,7 +67,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...) noexcept;
static inline void static inline void
LogWarning(const Domain &domain, const char *msg) noexcept LogWarning(const Domain &domain, const char *msg) noexcept
{ {
Log(domain, LogLevel::WARNING, msg); Log(LogLevel::WARNING, domain, msg);
} }
gcc_printf(2,3) gcc_printf(2,3)
@ -77,7 +77,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...) noexcept;
static inline void static inline void
LogError(const Domain &domain, const char *msg) noexcept LogError(const Domain &domain, const char *msg) noexcept
{ {
Log(domain, LogLevel::ERROR, msg); Log(LogLevel::ERROR, domain, msg);
} }
void void

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -176,7 +176,7 @@ FileLog(const Domain &domain, const char *message) noexcept
#endif /* !ANDROID */ #endif /* !ANDROID */
void void
Log(const Domain &domain, LogLevel level, const char *msg) noexcept Log(LogLevel level, const Domain &domain, const char *msg) noexcept
{ {
#ifdef ANDROID #ifdef ANDROID
__android_log_print(ToAndroidLogLevel(level), "MPD", __android_log_print(ToAndroidLogLevel(level), "MPD",

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -25,7 +25,7 @@
#include <stdarg.h> #include <stdarg.h>
void void
LogFormatV(const Domain &domain, LogLevel level, LogFormatV(LogLevel level, const Domain &domain,
const char *fmt, va_list ap) noexcept; const char *fmt, va_list ap) noexcept;
#endif /* LOG_H */ #endif /* LOG_H */

View File

@ -70,8 +70,8 @@ fluidsynth_mpd_log_function(int level,
char *message, char *message,
void *) void *)
{ {
Log(fluidsynth_domain, Log(fluidsynth_level_to_mpd(fluid_log_level(level)),
fluidsynth_level_to_mpd(fluid_log_level(level)), fluidsynth_domain,
message); message);
} }

View File

@ -62,6 +62,6 @@ FfmpegLogCallback(gcc_unused void *ptr, int level, const char *fmt, va_list vl)
ffmpeg_domain.GetName(), ffmpeg_domain.GetName(),
cls->item_name(ptr)); cls->item_name(ptr));
const Domain d(domain); const Domain d(domain);
LogFormatV(d, FfmpegImportLogLevel(level), fmt, vl); LogFormatV(FfmpegImportLogLevel(level), d, fmt, vl);
} }
} }

View File

@ -54,7 +54,7 @@ FormatFatalError(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(fatal_error_domain, LogLevel::ERROR, fmt, ap); LogFormatV(LogLevel::ERROR, fatal_error_domain, fmt, ap);
va_end(ap); va_end(ap);
Abort(); Abort();

View File

@ -25,7 +25,7 @@
#include <stdio.h> #include <stdio.h>
void void
Log(const Domain &domain, gcc_unused LogLevel level, const char *msg) noexcept Log(LogLevel, const Domain &domain, const char *msg) noexcept
{ {
fprintf(stderr, "[%s] %s\n", domain.GetName(), msg); fprintf(stderr, "[%s] %s\n", domain.GetName(), msg);
} }