Partition, ...: use libfmt for logging

This commit is contained in:
Max Kellermann
2021-06-24 20:22:48 +02:00
parent 0185d58a2b
commit 6f539cfcd6
44 changed files with 320 additions and 296 deletions

View File

@@ -20,9 +20,9 @@
#include "config.h"
#include "DecoderList.hxx"
#include "DecoderPlugin.hxx"
#include "Domain.hxx"
#include "decoder/Features.h"
#include "PluginUnavailable.hxx"
#include "Log.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "config/Data.hxx"
#include "config/Block.hxx"
#include "plugins/AudiofileDecoderPlugin.hxx"
@@ -49,6 +49,8 @@
#include "plugins/FluidsynthDecoderPlugin.hxx"
#include "plugins/SidplayDecoderPlugin.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx"
#include "PluginUnavailable.hxx"
#include <iterator>
@@ -160,9 +162,9 @@ decoder_plugin_init_all(const ConfigData &config)
if (plugin.Init(*param))
decoder_plugins_enabled[i] = true;
} catch (const PluginUnavailable &e) {
FormatError(e,
"Decoder plugin '%s' is unavailable",
plugin.name);
FmtError(decoder_domain,
"Decoder plugin '{}' is unavailable: {}",
plugin.name, std::current_exception());
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize decoder plugin '%s'",
plugin.name));

View File

@@ -3,6 +3,7 @@ decoder_features = configuration_data()
decoder_api = static_library(
'decoder_api',
'DecoderAPI.cxx',
'Domain.cxx',
'Reader.cxx',
'DecoderBuffer.cxx',
'DecoderPlugin.cxx',

View File

@@ -357,24 +357,24 @@ faad_stream_decode(DecoderClient &client, InputStream &is,
faad_decoder_decode(decoder, buffer, &frame_info);
if (frame_info.error > 0) {
FormatWarning(faad_decoder_domain,
"error decoding AAC stream: %s",
NeAACDecGetErrorMessage(frame_info.error));
FmtWarning(faad_decoder_domain,
"error decoding AAC stream: {}",
NeAACDecGetErrorMessage(frame_info.error));
break;
}
if (frame_info.channels != audio_format.channels) {
FormatNotice(faad_decoder_domain,
"channel count changed from %u to %u",
audio_format.channels, frame_info.channels);
FmtNotice(faad_decoder_domain,
"channel count changed from {} to {}",
audio_format.channels, frame_info.channels);
break;
}
if (frame_info.samplerate != audio_format.sample_rate) {
FormatNotice(faad_decoder_domain,
"sample rate changed from %u to %lu",
audio_format.sample_rate,
(unsigned long)frame_info.samplerate);
FmtNotice(faad_decoder_domain,
"sample rate changed from {} to {}",
audio_format.sample_rate,
frame_info.samplerate);
break;
}

View File

@@ -270,9 +270,9 @@ FfmpegReceiveFrames(DecoderClient &client, InputStream *is,
{
char msg[256];
av_strerror(err, msg, sizeof(msg));
FormatWarning(ffmpeg_domain,
"avcodec_send_packet() failed: %s",
msg);
FmtWarning(ffmpeg_domain,
"avcodec_send_packet() failed: {}",
msg);
}
return DecoderCommand::STOP;
@@ -326,8 +326,8 @@ ffmpeg_send_packet(DecoderClient &client, InputStream *is,
{
char msg[256];
av_strerror(err, msg, sizeof(msg));
FormatWarning(ffmpeg_domain,
"avcodec_send_packet() failed: %s", msg);
FmtWarning(ffmpeg_domain,
"avcodec_send_packet() failed: {}", msg);
}
return DecoderCommand::NONE;
@@ -355,13 +355,13 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) noexcept
const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
sample_fmt);
if (name != nullptr)
FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt);
FmtError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: {} ({})",
name, sample_fmt);
else
FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %d",
sample_fmt);
FmtError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: {}",
sample_fmt);
return SampleFormat::UNDEFINED;
}
@@ -499,8 +499,8 @@ FfmpegDecode(DecoderClient &client, InputStream *input,
const AVCodecDescriptor *codec_descriptor =
avcodec_descriptor_get(codec_params.codec_id);
if (codec_descriptor != nullptr)
FormatDebug(ffmpeg_domain, "codec '%s'",
codec_descriptor->name);
FmtDebug(ffmpeg_domain, "codec '{}'",
codec_descriptor->name);
AVCodec *codec = avcodec_find_decoder(codec_params.codec_id);
@@ -602,8 +602,8 @@ ffmpeg_decode(DecoderClient &client, InputStream &input)
FfmpegOpenInput(stream.io, input.GetURI(), nullptr);
const auto *input_format = format_context->iformat;
FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
input_format->name, input_format->long_name);
FmtDebug(ffmpeg_domain, "detected input format '{}' ({})",
input_format->name, input_format->long_name);
FfmpegDecode(client, &input, *format_context);
}
@@ -668,8 +668,8 @@ ffmpeg_uri_decode(DecoderClient &client, const char *uri)
FfmpegOpenInput(nullptr, uri, nullptr);
const auto *input_format = format_context->iformat;
FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
input_format->name, input_format->long_name);
FmtDebug(ffmpeg_domain, "detected input format '{}' ({})",
input_format->name, input_format->long_name);
FfmpegDecode(client, nullptr, *format_context);
}

View File

@@ -20,6 +20,7 @@
#include "config.h"
#include "MikmodDecoderPlugin.hxx"
#include "../DecoderAPI.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "tag/Handler.hxx"
#include "fs/Path.hxx"
#include "util/Domain.hxx"
@@ -126,9 +127,9 @@ mikmod_decoder_init(const ConfigBlock &block)
DMODE_16BITS);
if (MikMod_Init(params)) {
FormatError(mikmod_domain,
"Could not init MikMod: %s",
MikMod_strerror(MikMod_errno));
FmtError(mikmod_domain,
"Could not init MikMod: {}",
MikMod_strerror(MikMod_errno));
return false;
}
@@ -155,8 +156,7 @@ mikmod_decoder_file_decode(DecoderClient &client, Path path_fs)
handle = Player_Load(path2, 128, 0);
if (handle == nullptr) {
FormatError(mikmod_domain,
"failed to open mod: %s", path_fs.c_str());
FmtError(mikmod_domain, "failed to open mod: {}", path_fs);
return;
}
@@ -189,8 +189,7 @@ mikmod_decoder_scan_file(Path path_fs, TagHandler &handler) noexcept
MODULE *handle = Player_Load(path2, 128, 0);
if (handle == nullptr) {
FormatDebug(mikmod_domain,
"Failed to open file: %s", path_fs.c_str());
FmtDebug(mikmod_domain, "Failed to open file: {}", path_fs);
return false;
}

View File

@@ -65,9 +65,9 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
{
int error = mpg123_open(handle, path_fs);
if (error != MPG123_OK) {
FormatWarning(mpg123_domain,
"libmpg123 failed to open %s: %s",
path_fs, mpg123_plain_strerror(error));
FmtWarning(mpg123_domain,
"libmpg123 failed to open {}: {}",
path_fs, mpg123_plain_strerror(error));
return false;
}
@@ -77,17 +77,17 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
int channels, encoding;
error = mpg123_getformat(handle, &rate, &channels, &encoding);
if (error != MPG123_OK) {
FormatWarning(mpg123_domain,
"mpg123_getformat() failed: %s",
mpg123_plain_strerror(error));
FmtWarning(mpg123_domain,
"mpg123_getformat() failed: {}",
mpg123_plain_strerror(error));
return false;
}
if (encoding != MPG123_ENC_SIGNED_16) {
/* other formats not yet implemented */
FormatWarning(mpg123_domain,
"expected MPG123_ENC_SIGNED_16, got %d",
encoding);
FmtWarning(mpg123_domain,
"expected MPG123_ENC_SIGNED_16, got {}",
encoding);
return false;
}
@@ -187,9 +187,9 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs)
int error;
mpg123_handle *const handle = mpg123_new(nullptr, &error);
if (handle == nullptr) {
FormatError(mpg123_domain,
"mpg123_new() failed: %s",
mpg123_plain_strerror(error));
FmtError(mpg123_domain,
"mpg123_new() failed: {}",
mpg123_plain_strerror(error));
return;
}
@@ -238,9 +238,9 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs)
error = mpg123_read(handle, buffer, sizeof(buffer), &nbytes);
if (error != MPG123_OK) {
if (error != MPG123_DONE)
FormatWarning(mpg123_domain,
"mpg123_read() failed: %s",
mpg123_plain_strerror(error));
FmtWarning(mpg123_domain,
"mpg123_read() failed: {}",
mpg123_plain_strerror(error));
break;
}
@@ -277,9 +277,9 @@ mpd_mpg123_scan_file(Path path_fs, TagHandler &handler) noexcept
int error;
mpg123_handle *const handle = mpg123_new(nullptr, &error);
if (handle == nullptr) {
FormatError(mpg123_domain,
"mpg123_new() failed: %s",
mpg123_plain_strerror(error));
FmtError(mpg123_domain,
"mpg123_new() failed: {}",
mpg123_plain_strerror(error));
return false;
}