Commit 060814da authored by Max Kellermann's avatar Max Kellermann

Log: new logging library API

Prepare to migrate away from GLib. Currently, we're still using GLib as a backend.
parent c53492a7
...@@ -129,6 +129,7 @@ src_mpd_SOURCES = \ ...@@ -129,6 +129,7 @@ src_mpd_SOURCES = \
src/FilterPlugin.cxx src/FilterPlugin.hxx \ src/FilterPlugin.cxx src/FilterPlugin.hxx \
src/FilterInternal.hxx \ src/FilterInternal.hxx \
src/FilterRegistry.cxx src/FilterRegistry.hxx \ src/FilterRegistry.cxx src/FilterRegistry.hxx \
src/UpdateDomain.cxx src/UpdateDomain.hxx \
src/UpdateGlue.cxx src/UpdateGlue.hxx \ src/UpdateGlue.cxx src/UpdateGlue.hxx \
src/UpdateQueue.cxx src/UpdateQueue.hxx \ src/UpdateQueue.cxx src/UpdateQueue.hxx \
src/UpdateIO.cxx src/UpdateIO.hxx \ src/UpdateIO.cxx src/UpdateIO.hxx \
...@@ -154,7 +155,8 @@ src_mpd_SOURCES = \ ...@@ -154,7 +155,8 @@ src_mpd_SOURCES = \
src/ClientSubscribe.cxx src/ClientSubscribe.hxx \ src/ClientSubscribe.cxx src/ClientSubscribe.hxx \
src/ClientFile.cxx src/ClientFile.hxx \ src/ClientFile.cxx src/ClientFile.hxx \
src/Listen.cxx src/Listen.hxx \ src/Listen.cxx src/Listen.hxx \
src/Log.cxx src/Log.hxx \ src/LogInit.cxx src/LogInit.hxx \
src/Log.cxx src/Log.hxx src/LogV.hxx \
src/ls.cxx src/ls.hxx \ src/ls.cxx src/ls.hxx \
src/IOThread.cxx src/IOThread.hxx \ src/IOThread.cxx src/IOThread.hxx \
src/Main.cxx src/Main.hxx \ src/Main.cxx src/Main.hxx \
...@@ -233,6 +235,7 @@ endif ...@@ -233,6 +235,7 @@ endif
if ENABLE_INOTIFY if ENABLE_INOTIFY
src_mpd_SOURCES += \ src_mpd_SOURCES += \
src/InotifyDomain.cxx src/InotifyDomain.hxx \
src/InotifySource.cxx src/InotifySource.hxx \ src/InotifySource.cxx src/InotifySource.hxx \
src/InotifyQueue.cxx src/InotifyQueue.hxx \ src/InotifyQueue.cxx src/InotifyQueue.hxx \
src/InotifyUpdate.cxx src/InotifyUpdate.hxx src/InotifyUpdate.cxx src/InotifyUpdate.hxx
...@@ -523,6 +526,7 @@ libdecoder_plugins_a_SOURCES += \ ...@@ -523,6 +526,7 @@ libdecoder_plugins_a_SOURCES += \
src/decoder/OggUtil.hxx \ src/decoder/OggUtil.hxx \
src/decoder/OggSyncState.hxx \ src/decoder/OggSyncState.hxx \
src/decoder/OggFind.cxx src/decoder/OggFind.hxx \ src/decoder/OggFind.cxx src/decoder/OggFind.hxx \
src/decoder/OpusDomain.cxx src/decoder/OpusDomain.hxx \
src/decoder/OpusReader.hxx \ src/decoder/OpusReader.hxx \
src/decoder/OpusHead.hxx \ src/decoder/OpusHead.hxx \
src/decoder/OpusHead.cxx \ src/decoder/OpusHead.cxx \
...@@ -557,6 +561,7 @@ endif ...@@ -557,6 +561,7 @@ endif
if ENABLE_VORBIS_DECODER if ENABLE_VORBIS_DECODER
libdecoder_plugins_a_SOURCES += \ libdecoder_plugins_a_SOURCES += \
src/decoder/VorbisDomain.cxx src/decoder/VorbisDomain.hxx \
src/decoder/VorbisComments.cxx src/decoder/VorbisComments.hxx \ src/decoder/VorbisComments.cxx src/decoder/VorbisComments.hxx \
src/decoder/VorbisDecoderPlugin.cxx src/decoder/VorbisDecoderPlugin.h src/decoder/VorbisDecoderPlugin.cxx src/decoder/VorbisDecoderPlugin.h
endif endif
...@@ -567,6 +572,7 @@ libdecoder_plugins_a_SOURCES += \ ...@@ -567,6 +572,7 @@ libdecoder_plugins_a_SOURCES += \
src/decoder/FlacIOHandle.cxx src/decoder/FlacIOHandle.hxx \ src/decoder/FlacIOHandle.cxx src/decoder/FlacIOHandle.hxx \
src/decoder/FlacMetadata.cxx src/decoder/FlacMetadata.hxx \ src/decoder/FlacMetadata.cxx src/decoder/FlacMetadata.hxx \
src/decoder/FlacPcm.cxx src/decoder/FlacPcm.hxx \ src/decoder/FlacPcm.cxx src/decoder/FlacPcm.hxx \
src/decoder/FlacDomain.cxx src/decoder/FlacDomain.hxx \
src/decoder/FlacCommon.cxx src/decoder/FlacCommon.hxx \ src/decoder/FlacCommon.cxx src/decoder/FlacCommon.hxx \
src/decoder/FlacDecoderPlugin.cxx \ src/decoder/FlacDecoderPlugin.cxx \
src/decoder/FlacDecoderPlugin.h src/decoder/FlacDecoderPlugin.h
...@@ -1062,13 +1068,17 @@ test_read_conf_LDADD = \ ...@@ -1062,13 +1068,17 @@ test_read_conf_LDADD = \
libsystem.a \ libsystem.a \
libfs.a \ libfs.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_conf_SOURCES = test/read_conf.cxx test_read_conf_SOURCES = \
src/Log.cxx \
test/read_conf.cxx
test_run_resolver_LDADD = \ test_run_resolver_LDADD = \
libsystem.a \ libsystem.a \
libutil.a \ libutil.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_resolver_SOURCES = test/run_resolver.cxx test_run_resolver_SOURCES = \
src/Log.cxx \
test/run_resolver.cxx
test_DumpDatabase_LDADD = \ test_DumpDatabase_LDADD = \
$(DB_LIBS) \ $(DB_LIBS) \
...@@ -1079,6 +1089,7 @@ test_DumpDatabase_LDADD = \ ...@@ -1079,6 +1089,7 @@ test_DumpDatabase_LDADD = \
libfs.a \ libfs.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
src/Log.cxx \
src/DatabaseError.cxx \ src/DatabaseError.cxx \
src/DatabaseRegistry.cxx \ src/DatabaseRegistry.cxx \
src/DatabaseSelection.cxx \ src/DatabaseSelection.cxx \
...@@ -1102,6 +1113,7 @@ test_run_input_LDADD = \ ...@@ -1102,6 +1113,7 @@ test_run_input_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_input_SOURCES = test/run_input.cxx \ test_run_input_SOURCES = test/run_input.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/TagSave.cxx src/TagSave.cxx
...@@ -1118,6 +1130,7 @@ test_visit_archive_LDADD = \ ...@@ -1118,6 +1130,7 @@ test_visit_archive_LDADD = \
libfs.a \ libfs.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_visit_archive_SOURCES = test/visit_archive.cxx \ test_visit_archive_SOURCES = test/visit_archive.cxx \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/InputStream.cxx src/InputStream.cxx
...@@ -1139,6 +1152,7 @@ test_dump_text_file_LDADD = \ ...@@ -1139,6 +1152,7 @@ test_dump_text_file_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_text_file_SOURCES = test/dump_text_file.cxx \ test_dump_text_file_SOURCES = test/dump_text_file.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/TextInputStream.cxx src/TextInputStream.cxx
...@@ -1158,6 +1172,7 @@ test_dump_playlist_LDADD = \ ...@@ -1158,6 +1172,7 @@ test_dump_playlist_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_playlist_SOURCES = test/dump_playlist.cxx \ test_dump_playlist_SOURCES = test/dump_playlist.cxx \
$(DECODER_SRC) \ $(DECODER_SRC) \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/Song.cxx src/TagSave.cxx \ src/Song.cxx src/TagSave.cxx \
src/TagFile.cxx \ src/TagFile.cxx \
...@@ -1185,6 +1200,7 @@ test_run_decoder_LDADD = \ ...@@ -1185,6 +1200,7 @@ test_run_decoder_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_decoder_SOURCES = test/run_decoder.cxx \ test_run_decoder_SOURCES = test/run_decoder.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/ReplayGainInfo.cxx \ src/ReplayGainInfo.cxx \
src/AudioFormat.cxx src/CheckAudioFormat.cxx \ src/AudioFormat.cxx src/CheckAudioFormat.cxx \
...@@ -1206,6 +1222,7 @@ test_read_tags_LDADD = \ ...@@ -1206,6 +1222,7 @@ test_read_tags_LDADD = \
libutil.a \ libutil.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_tags_SOURCES = test/read_tags.cxx \ test_read_tags_SOURCES = test/read_tags.cxx \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/ReplayGainInfo.cxx \ src/ReplayGainInfo.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
...@@ -1216,7 +1233,9 @@ test_dump_rva2_LDADD = \ ...@@ -1216,7 +1233,9 @@ test_dump_rva2_LDADD = \
$(TAG_LIBS) \ $(TAG_LIBS) \
libutil.a \ libutil.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_rva2_SOURCES = test/dump_rva2.cxx test_dump_rva2_SOURCES = \
src/Log.cxx \
test/dump_rva2.cxx
endif endif
test_run_filter_LDADD = \ test_run_filter_LDADD = \
...@@ -1229,6 +1248,7 @@ test_run_filter_LDADD = \ ...@@ -1229,6 +1248,7 @@ test_run_filter_LDADD = \
test_run_filter_SOURCES = test/run_filter.cxx \ test_run_filter_SOURCES = test/run_filter.cxx \
test/FakeReplayGainConfig.cxx \ test/FakeReplayGainConfig.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/FilterPlugin.cxx src/FilterRegistry.cxx \ src/FilterPlugin.cxx src/FilterRegistry.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \ src/AudioFormat.cxx \
...@@ -1248,6 +1268,7 @@ if ENABLE_ENCODER ...@@ -1248,6 +1268,7 @@ if ENABLE_ENCODER
noinst_PROGRAMS += test/run_encoder noinst_PROGRAMS += test/run_encoder
test_run_encoder_SOURCES = test/run_encoder.cxx \ test_run_encoder_SOURCES = test/run_encoder.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \ src/AudioFormat.cxx \
src/AudioParser.cxx src/AudioParser.cxx
...@@ -1266,6 +1287,7 @@ if ENABLE_VORBIS_ENCODER ...@@ -1266,6 +1287,7 @@ if ENABLE_VORBIS_ENCODER
noinst_PROGRAMS += test/test_vorbis_encoder noinst_PROGRAMS += test/test_vorbis_encoder
test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.cxx \ test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \ src/AudioFormat.cxx \
src/AudioParser.cxx \ src/AudioParser.cxx \
...@@ -1302,6 +1324,7 @@ test_run_normalize_LDADD = \ ...@@ -1302,6 +1324,7 @@ test_run_normalize_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_convert_SOURCES = test/run_convert.cxx \ test_run_convert_SOURCES = test/run_convert.cxx \
src/Log.cxx \
src/AudioFormat.cxx \ src/AudioFormat.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
src/AudioParser.cxx src/AudioParser.cxx
...@@ -1326,6 +1349,7 @@ test_run_output_LDADD = $(MPD_LIBS) \ ...@@ -1326,6 +1349,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
test_run_output_SOURCES = test/run_output.cxx \ test_run_output_SOURCES = test/run_output.cxx \
test/FakeReplayGainConfig.cxx \ test/FakeReplayGainConfig.cxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/CheckAudioFormat.cxx \ src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \ src/AudioFormat.cxx \
...@@ -1353,6 +1377,7 @@ test_read_mixer_LDADD = \ ...@@ -1353,6 +1377,7 @@ test_read_mixer_LDADD = \
libfs.a \ libfs.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_mixer_SOURCES = test/read_mixer.cxx \ test_read_mixer_SOURCES = test/read_mixer.cxx \
src/Log.cxx \
src/MixerControl.cxx \ src/MixerControl.cxx \
src/FilterPlugin.cxx \ src/FilterPlugin.cxx \
src/filter/VolumeFilterPlugin.cxx src/filter/VolumeFilterPlugin.cxx
...@@ -1372,6 +1397,8 @@ endif ...@@ -1372,6 +1397,8 @@ endif
if ENABLE_INOTIFY if ENABLE_INOTIFY
noinst_PROGRAMS += test/run_inotify noinst_PROGRAMS += test/run_inotify
test_run_inotify_SOURCES = test/run_inotify.cxx \ test_run_inotify_SOURCES = test/run_inotify.cxx \
src/Log.cxx \
src/InotifyDomain.cxx \
src/InotifySource.cxx src/InotifySource.cxx
test_run_inotify_LDADD = \ test_run_inotify_LDADD = \
libevent.a \ libevent.a \
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
foo(const char *abc, int xyz) foo(const char *abc, int xyz)
{ {
if (abc == NULL) { if (abc == NULL) {
g_warning("Foo happened!\n"); LogWarning("Foo happened!");
return -1; return -1;
} }
......
...@@ -19,15 +19,17 @@ ...@@ -19,15 +19,17 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "ArchiveLookup.hxx" #include "ArchiveLookup.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <stdio.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <glib.h>
static constexpr Domain archive_domain("archive");
/** /**
* *
...@@ -65,7 +67,8 @@ bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix ...@@ -65,7 +67,8 @@ bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix
//try to stat if its real directory //try to stat if its real directory
if (stat(pathdupe, &st_info) == -1) { if (stat(pathdupe, &st_info) == -1) {
if (errno != ENOTDIR) { if (errno != ENOTDIR) {
g_warning("stat %s failed (errno=%d)\n", pathdupe, errno); FormatErrno(archive_domain,
"Failed to stat %s", pathdupe);
break; break;
} }
} else { } else {
...@@ -92,7 +95,9 @@ bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix ...@@ -92,7 +95,9 @@ bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix
} }
break; break;
} else { } else {
g_warning("not a regular file %s\n", pathdupe); FormatError(archive_domain,
"Not a regular file: %s",
pathdupe);
break; break;
} }
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "config.h" #include "config.h"
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
#include "util/Domain.hxx"
const Domain client_domain("client");
int client_get_uid(const Client *client) int client_get_uid(const Client *client)
{ {
......
...@@ -20,13 +20,12 @@ ...@@ -20,13 +20,12 @@
#include "config.h" #include "config.h"
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
void void
Client::OnSocketError(Error &&error) Client::OnSocketError(Error &&error)
{ {
g_warning("error on client %d: %s", num, error.GetMessage()); FormatError(error, "error on client %d", num);
SetExpired(); SetExpired();
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -37,7 +38,7 @@ Client::OnTimeout() ...@@ -37,7 +38,7 @@ Client::OnTimeout()
{ {
if (!IsExpired()) { if (!IsExpired()) {
assert(!idle_waiting); assert(!idle_waiting);
g_debug("[%u] timeout", num); FormatDebug(client_domain, "[%u] timeout", num);
} }
Close(); Close();
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
#include <string> #include <string>
#include <list> #include <list>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "client"
enum { enum {
CLIENT_MAX_SUBSCRIPTIONS = 16, CLIENT_MAX_SUBSCRIPTIONS = 16,
CLIENT_MAX_MESSAGES = 64, CLIENT_MAX_MESSAGES = 64,
...@@ -123,6 +120,8 @@ private: ...@@ -123,6 +120,8 @@ private:
virtual void OnTimeout() override; virtual void OnTimeout() override;
}; };
extern const class Domain client_domain;
extern int client_timeout; extern int client_timeout;
extern size_t client_max_command_list_size; extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size; extern size_t client_max_output_buffer_size;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "system/Resolver.hxx" #include "system/Resolver.hxx"
#include "Permission.hxx" #include "Permission.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -40,9 +41,6 @@ ...@@ -40,9 +41,6 @@
#include <tcpd.h> #include <tcpd.h>
#endif #endif
#define LOG_LEVEL_SECURE G_LOG_LEVEL_INFO
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n"; static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
Client::Client(EventLoop &_loop, Partition &_partition, Client::Client(EventLoop &_loop, Partition &_partition,
...@@ -82,7 +80,7 @@ client_new(EventLoop &loop, Partition &partition, ...@@ -82,7 +80,7 @@ client_new(EventLoop &loop, Partition &partition,
if (!hosts_access(&req)) { if (!hosts_access(&req)) {
/* tcp wrappers says no */ /* tcp wrappers says no */
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, FormatWarning(client_domain,
"libwrap refused connection (libwrap=%s) from %s", "libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr); progname, hostaddr);
...@@ -97,7 +95,7 @@ client_new(EventLoop &loop, Partition &partition, ...@@ -97,7 +95,7 @@ client_new(EventLoop &loop, Partition &partition,
ClientList &client_list = *partition.instance.client_list; ClientList &client_list = *partition.instance.client_list;
if (client_list.IsFull()) { if (client_list.IsFull()) {
g_warning("Max Connections Reached!"); LogWarning(client_domain, "Max connections reached");
close_socket(fd); close_socket(fd);
return; return;
} }
...@@ -110,8 +108,7 @@ client_new(EventLoop &loop, Partition &partition, ...@@ -110,8 +108,7 @@ client_new(EventLoop &loop, Partition &partition,
client_list.Add(*client); client_list.Add(*client);
remote = sockaddr_to_string(sa, sa_length, IgnoreError()); remote = sockaddr_to_string(sa, sa_length, IgnoreError());
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, FormatInfo(client_domain, "[%u] opened from %s", client->num, remote);
"[%u] opened from %s", client->num, remote);
g_free(remote); g_free(remote);
} }
...@@ -122,6 +119,6 @@ Client::Close() ...@@ -122,6 +119,6 @@ Client::Close()
SetExpired(); SetExpired();
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, "[%u] closed", num); FormatInfo(client_domain, "[%u] closed", num);
delete this; delete this;
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
#include "protocol/Result.hxx" #include "protocol/Result.hxx"
#include "AllCommands.hxx" #include "AllCommands.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -40,10 +41,9 @@ client_process_command_list(Client *client, bool list_ok, ...@@ -40,10 +41,9 @@ client_process_command_list(Client *client, bool list_ok,
for (auto &&i : list) { for (auto &&i : list) {
char *cmd = &*i.begin(); char *cmd = &*i.begin();
g_debug("command_process_list: process command \"%s\"", FormatDebug(client_domain, "process command \"%s\"", cmd);
cmd);
ret = command_process(client, num++, cmd); ret = command_process(client, num++, cmd);
g_debug("command_process_list: command returned %i", ret); FormatDebug(client_domain, "command returned %i", ret);
if (ret != COMMAND_RETURN_OK || client->IsExpired()) if (ret != COMMAND_RETURN_OK || client->IsExpired())
break; break;
else if (list_ok) else if (list_ok)
...@@ -73,14 +73,16 @@ client_process_line(Client *client, char *line) ...@@ -73,14 +73,16 @@ client_process_line(Client *client, char *line)
} else if (client->idle_waiting) { } else if (client->idle_waiting) {
/* during idle mode, clients must not send anything /* during idle mode, clients must not send anything
except "noidle" */ except "noidle" */
g_warning("[%u] command \"%s\" during idle", FormatWarning(client_domain,
"[%u] command \"%s\" during idle",
client->num, line); client->num, line);
return COMMAND_RETURN_CLOSE; return COMMAND_RETURN_CLOSE;
} }
if (client->cmd_list.IsActive()) { if (client->cmd_list.IsActive()) {
if (strcmp(line, CLIENT_LIST_MODE_END) == 0) { if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
g_debug("[%u] process command list", FormatDebug(client_domain,
"[%u] process command list",
client->num); client->num);
auto &&cmd_list = client->cmd_list.Commit(); auto &&cmd_list = client->cmd_list.Commit();
...@@ -88,7 +90,8 @@ client_process_line(Client *client, char *line) ...@@ -88,7 +90,8 @@ client_process_line(Client *client, char *line)
ret = client_process_command_list(client, ret = client_process_command_list(client,
client->cmd_list.IsOKMode(), client->cmd_list.IsOKMode(),
std::move(cmd_list)); std::move(cmd_list));
g_debug("[%u] process command " FormatDebug(client_domain,
"[%u] process command "
"list returned %i", client->num, ret); "list returned %i", client->num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == COMMAND_RETURN_CLOSE ||
...@@ -101,7 +104,8 @@ client_process_line(Client *client, char *line) ...@@ -101,7 +104,8 @@ client_process_line(Client *client, char *line)
client->cmd_list.Reset(); client->cmd_list.Reset();
} else { } else {
if (!client->cmd_list.Add(line)) { if (!client->cmd_list.Add(line)) {
g_warning("[%u] command list size " FormatWarning(client_domain,
"[%u] command list size "
"is larger than the max (%lu)", "is larger than the max (%lu)",
client->num, client->num,
(unsigned long)client_max_command_list_size); (unsigned long)client_max_command_list_size);
...@@ -118,10 +122,12 @@ client_process_line(Client *client, char *line) ...@@ -118,10 +122,12 @@ client_process_line(Client *client, char *line)
client->cmd_list.Begin(true); client->cmd_list.Begin(true);
ret = COMMAND_RETURN_OK; ret = COMMAND_RETURN_OK;
} else { } else {
g_debug("[%u] process command \"%s\"", FormatDebug(client_domain,
"[%u] process command \"%s\"",
client->num, line); client->num, line);
ret = command_process(client, 0, line); ret = command_process(client, 0, line);
g_debug("[%u] command returned %i", FormatDebug(client_domain,
"[%u] command returned %i",
client->num, ret); client->num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == COMMAND_RETURN_CLOSE ||
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "DatabaseError.hxx" #include "DatabaseError.hxx"
#include "protocol/Result.hxx" #include "protocol/Result.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -93,7 +94,7 @@ print_error(Client *client, const Error &error) ...@@ -93,7 +94,7 @@ print_error(Client *client, const Error &error)
assert(client != NULL); assert(client != NULL);
assert(error.IsDefined()); assert(error.IsDefined());
g_warning("%s", error.GetMessage()); LogError(error);
if (error.IsDomain(playlist_domain)) { if (error.IsDomain(playlist_domain)) {
return print_playlist_result(client, return print_playlist_result(client,
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "CommandLine.hxx" #include "CommandLine.hxx"
#include "ls.hxx" #include "ls.hxx"
#include "LogInit.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
...@@ -197,7 +198,8 @@ parse_cmdline(int argc, char **argv, struct options *options, ...@@ -197,7 +198,8 @@ parse_cmdline(int argc, char **argv, struct options *options,
options->daemon = !option_no_daemon; options->daemon = !option_no_daemon;
if (option_no_config) { if (option_no_config) {
g_debug("Ignoring config, using daemon defaults\n"); LogDebug(cmdline_domain,
"Ignoring config, using daemon defaults");
return true; return true;
} else if (argc <= 1) { } else if (argc <= 1) {
/* default configuration file path */ /* default configuration file path */
......
...@@ -28,17 +28,13 @@ ...@@ -28,17 +28,13 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "config"
#define MAX_STRING_SIZE MPD_PATH_MAX+80 #define MAX_STRING_SIZE MPD_PATH_MAX+80
#define CONF_COMMENT '#' #define CONF_COMMENT '#'
...@@ -261,7 +257,7 @@ ReadConfigFile(ConfigData &config_data, const Path &path, Error &error) ...@@ -261,7 +257,7 @@ ReadConfigFile(ConfigData &config_data, const Path &path, Error &error)
assert(!path.IsNull()); assert(!path.IsNull());
const std::string path_utf8 = path.ToUTF8(); const std::string path_utf8 = path.ToUTF8();
g_debug("loading file %s", path_utf8.c_str()); FormatDebug(config_file_domain, "loading file %s", path_utf8.c_str());
FILE *fp = FOpen(path, FOpenMode::ReadText); FILE *fp = FOpen(path, FOpenMode::ReadText);
if (fp == nullptr) { if (fp == nullptr) {
......
...@@ -23,18 +23,15 @@ ...@@ -23,18 +23,15 @@
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "ConfigFile.hxx" #include "ConfigFile.hxx"
#include "ConfigPath.hxx" #include "ConfigPath.hxx"
#include "ConfigError.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "config"
static ConfigData config_data; static ConfigData config_data;
void config_global_finish(void) void config_global_finish(void)
...@@ -64,7 +61,8 @@ Check(const config_param *param) ...@@ -64,7 +61,8 @@ Check(const config_param *param)
for (const auto &i : param->block_params) { for (const auto &i : param->block_params) {
if (!i.used) if (!i.used)
g_warning("option '%s' on line %i was not recognized", FormatWarning(config_domain,
"option '%s' on line %i was not recognized",
i.name.c_str(), i.line); i.name.c_str(), i.line);
} }
} }
......
...@@ -21,23 +21,25 @@ ...@@ -21,23 +21,25 @@
#include "CrossFade.hxx" #include "CrossFade.hxx"
#include "MusicChunk.hxx" #include "MusicChunk.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <cmath> #include <cmath>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <glib.h>
#undef G_LOG_DOMAIN static constexpr Domain cross_fade_domain("cross_fade");
#define G_LOG_DOMAIN "crossfade"
#ifdef WIN32
#ifdef G_OS_WIN32
static char * static char *
strtok_r(char *str, const char *delim, gcc_unused char **saveptr) strtok_r(char *str, const char *delim, gcc_unused char **saveptr)
{ {
return strtok(str, delim); return strtok(str, delim);
} }
#endif #endif
static float mixramp_interpolate(char *ramp_list, float required_db) static float mixramp_interpolate(char *ramp_list, float required_db)
...@@ -123,14 +125,16 @@ unsigned cross_fade_calc(float duration, float total_time, ...@@ -123,14 +125,16 @@ unsigned cross_fade_calc(float duration, float total_time,
if (!std::isnan(mixramp_overlap) && if (!std::isnan(mixramp_overlap) &&
mixramp_delay <= mixramp_overlap) { mixramp_delay <= mixramp_overlap) {
chunks = (chunks_f * (mixramp_overlap - mixramp_delay)); chunks = (chunks_f * (mixramp_overlap - mixramp_delay));
g_debug("will overlap %d chunks, %fs", chunks, FormatDebug(cross_fade_domain,
"will overlap %d chunks, %fs", chunks,
mixramp_overlap - mixramp_delay); mixramp_overlap - mixramp_delay);
} }
} }
if (chunks > max_chunks) { if (chunks > max_chunks) {
chunks = max_chunks; chunks = max_chunks;
g_warning("audio_buffer_size too small for computed MixRamp overlap"); LogWarning(cross_fade_domain,
"audio_buffer_size too small for computed MixRamp overlap");
} }
return chunks; return chunks;
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -39,8 +41,7 @@ ...@@ -39,8 +41,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
#undef G_LOG_DOMAIN static constexpr Domain daemon_domain("daemon");
#define G_LOG_DOMAIN "daemon"
#ifndef WIN32 #ifndef WIN32
...@@ -170,7 +171,7 @@ daemonize_detach(void) ...@@ -170,7 +171,7 @@ daemonize_detach(void)
FatalError("no support for daemonizing"); FatalError("no support for daemonizing");
#endif #endif
g_debug("daemonized!"); LogDebug(daemon_domain, "daemonized");
} }
void void
...@@ -181,7 +182,7 @@ daemonize(bool detach) ...@@ -181,7 +182,7 @@ daemonize(bool detach)
if (!pidfile.IsNull()) { if (!pidfile.IsNull()) {
/* do this before daemon'izing so we can fail gracefully if we can't /* do this before daemon'izing so we can fail gracefully if we can't
* write to the pid file */ * write to the pid file */
g_debug("opening pid file"); LogDebug(daemon_domain, "opening pid file");
fp = FOpen(pidfile, "w+"); fp = FOpen(pidfile, "w+");
if (!fp) { if (!fp) {
const std::string utf8 = pidfile.ToUTF8(); const std::string utf8 = pidfile.ToUTF8();
...@@ -194,7 +195,7 @@ daemonize(bool detach) ...@@ -194,7 +195,7 @@ daemonize(bool detach)
daemonize_detach(); daemonize_detach();
if (!pidfile.IsNull()) { if (!pidfile.IsNull()) {
g_debug("writing pid file"); LogDebug(daemon_domain, "writing pid file");
fprintf(fp, "%lu\n", (unsigned long)getpid()); fprintf(fp, "%lu\n", (unsigned long)getpid());
fclose(fp); fclose(fp);
} }
......
...@@ -43,9 +43,6 @@ extern "C" { ...@@ -43,9 +43,6 @@ extern "C" {
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "database"
static Database *db; static Database *db;
static bool db_is_open; static bool db_is_open;
static bool is_simple; static bool is_simple;
......
...@@ -29,15 +29,13 @@ ...@@ -29,15 +29,13 @@
#include "tag/TagSettings.h" #include "tag/TagSettings.h"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "database"
#define DIRECTORY_INFO_BEGIN "info_begin" #define DIRECTORY_INFO_BEGIN "info_begin"
#define DIRECTORY_INFO_END "info_end" #define DIRECTORY_INFO_END "info_end"
#define DB_FORMAT_PREFIX "format: " #define DB_FORMAT_PREFIX "format: "
...@@ -155,7 +153,7 @@ db_load_internal(TextFile &file, Directory *music_root, Error &error) ...@@ -155,7 +153,7 @@ db_load_internal(TextFile &file, Directory *music_root, Error &error)
} }
} }
g_debug("reading DB"); LogDebug(db_domain, "reading DB");
db_lock(); db_lock();
success = directory_load(file, music_root, error); success = directory_load(file, music_root, error);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "DecoderError.hxx"
#include "AudioConfig.hxx" #include "AudioConfig.hxx"
#include "replay_gain_config.h" #include "replay_gain_config.h"
#include "MusicChunk.hxx" #include "MusicChunk.hxx"
...@@ -29,16 +30,12 @@ ...@@ -29,16 +30,12 @@
#include "Song.hxx" #include "Song.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder"
void void
decoder_initialized(struct decoder *decoder, decoder_initialized(struct decoder *decoder,
const AudioFormat audio_format, const AudioFormat audio_format,
...@@ -67,12 +64,12 @@ decoder_initialized(struct decoder *decoder, ...@@ -67,12 +64,12 @@ decoder_initialized(struct decoder *decoder,
dc->client_cond.signal(); dc->client_cond.signal();
dc->Unlock(); dc->Unlock();
g_debug("audio_format=%s, seekable=%s", FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
audio_format_to_string(dc->in_audio_format, &af_string), audio_format_to_string(dc->in_audio_format, &af_string),
seekable ? "true" : "false"); seekable ? "true" : "false");
if (dc->in_audio_format != dc->out_audio_format) if (dc->in_audio_format != dc->out_audio_format)
g_debug("converting to %s", FormatDebug(decoder_domain, "converting to %s",
audio_format_to_string(dc->out_audio_format, audio_format_to_string(dc->out_audio_format,
&af_string)); &af_string));
} }
...@@ -288,7 +285,7 @@ size_t decoder_read(struct decoder *decoder, ...@@ -288,7 +285,7 @@ size_t decoder_read(struct decoder *decoder,
assert(nbytes > 0 || error.IsDefined() || is->IsEOF()); assert(nbytes > 0 || error.IsDefined() || is->IsEOF());
if (gcc_unlikely(nbytes == 0 && error.IsDefined())) if (gcc_unlikely(nbytes == 0 && error.IsDefined()))
g_warning("%s", error.GetMessage()); LogError(error);
is->Unlock(); is->Unlock();
...@@ -404,7 +401,7 @@ decoder_data(struct decoder *decoder, ...@@ -404,7 +401,7 @@ decoder_data(struct decoder *decoder,
/* the PCM conversion has failed - stop /* the PCM conversion has failed - stop
playback, since we have no better way to playback, since we have no better way to
bail out */ bail out */
g_warning("%s", error.GetMessage()); LogError(error);
return DecoderCommand::STOP; return DecoderCommand::STOP;
} }
} }
......
...@@ -26,9 +26,6 @@ ...@@ -26,9 +26,6 @@
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder_control"
decoder_control::decoder_control() decoder_control::decoder_control()
:thread(nullptr), :thread(nullptr),
state(DecoderState::STOP), state(DecoderState::STOP),
......
...@@ -33,15 +33,16 @@ ...@@ -33,15 +33,16 @@
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "tag/ApeReplayGain.hxx" #include "tag/ApeReplayGain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET */ #include <stdio.h> /* for SEEK_SET */
#undef G_LOG_DOMAIN static constexpr Domain decoder_thread_domain("decoder_thread");
#define G_LOG_DOMAIN "decoder_thread"
/** /**
* Marks the current decoder command as "finished" and notifies the * Marks the current decoder command as "finished" and notifies the
...@@ -78,7 +79,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri) ...@@ -78,7 +79,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
input_stream *is = input_stream::Open(uri, dc->mutex, dc->cond, error); input_stream *is = input_stream::Open(uri, dc->mutex, dc->cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
return NULL; return NULL;
} }
...@@ -99,7 +100,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri) ...@@ -99,7 +100,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
if (!is->Check(error)) { if (!is->Check(error)) {
dc->Unlock(); dc->Unlock();
g_warning("%s", error.GetMessage()); LogError(error);
return NULL; return NULL;
} }
...@@ -122,7 +123,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin, ...@@ -122,7 +123,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
assert(input_stream->ready); assert(input_stream->ready);
assert(decoder->dc->state == DecoderState::START); assert(decoder->dc->state == DecoderState::START);
g_debug("probing plugin %s", plugin->name); FormatDebug(decoder_thread_domain, "probing plugin %s", plugin->name);
if (decoder->dc->command == DecoderCommand::STOP) if (decoder->dc->command == DecoderCommand::STOP)
return true; return true;
...@@ -155,7 +156,7 @@ decoder_file_decode(const struct decoder_plugin *plugin, ...@@ -155,7 +156,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
assert(g_path_is_absolute(path)); assert(g_path_is_absolute(path));
assert(decoder->dc->state == DecoderState::START); assert(decoder->dc->state == DecoderState::START);
g_debug("probing plugin %s", plugin->name); FormatDebug(decoder_thread_domain, "probing plugin %s", plugin->name);
if (decoder->dc->command == DecoderCommand::STOP) if (decoder->dc->command == DecoderCommand::STOP)
return true; return true;
......
...@@ -21,13 +21,15 @@ ...@@ -21,13 +21,15 @@
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigOption.hxx" #include "ConfigOption.hxx"
#include "util/Domain.hxx"
#include <glib.h> #include "Log.hxx"
extern "C" { extern "C" {
#include <despotify.h> #include <despotify.h>
} }
const Domain despotify_domain("despotify");
static struct despotify_session *g_session; static struct despotify_session *g_session;
static void (*registered_callbacks[8])(struct despotify_session *, static void (*registered_callbacks[8])(struct despotify_session *,
int, void *, void *); int, void *, void *);
...@@ -121,24 +123,27 @@ struct despotify_session *mpd_despotify_get_session(void) ...@@ -121,24 +123,27 @@ struct despotify_session *mpd_despotify_get_session(void)
high_bitrate = config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true); high_bitrate = config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true);
if (user == NULL || passwd == NULL) { if (user == NULL || passwd == NULL) {
g_debug("disabling despotify because account is not configured"); LogDebug(despotify_domain,
"disabling despotify because account is not configured");
return nullptr; return nullptr;
} }
if (!despotify_init()) { if (!despotify_init()) {
g_debug("Can't initialize despotify\n"); LogWarning(despotify_domain, "Can't initialize despotify");
return nullptr; return nullptr;
} }
g_session = despotify_init_client(callback, NULL, g_session = despotify_init_client(callback, NULL,
high_bitrate, true); high_bitrate, true);
if (!g_session) { if (!g_session) {
g_debug("Can't initialize despotify client\n"); LogWarning(despotify_domain,
"Can't initialize despotify client");
return nullptr; return nullptr;
} }
if (!despotify_authenticate(g_session, user, passwd)) { if (!despotify_authenticate(g_session, user, passwd)) {
g_debug("Can't authenticate despotify session\n"); LogWarning(despotify_domain,
"Can't authenticate despotify session");
despotify_exit(g_session); despotify_exit(g_session);
return nullptr; return nullptr;
} }
......
...@@ -24,6 +24,8 @@ struct Tag; ...@@ -24,6 +24,8 @@ struct Tag;
struct despotify_session; struct despotify_session;
struct ds_track; struct ds_track;
extern const class Domain despotify_domain;
/** /**
* Return the current despotify session. * Return the current despotify session.
* *
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
...@@ -26,21 +27,26 @@ ...@@ -26,21 +27,26 @@
#include "ExcludeList.hxx" #include "ExcludeList.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
static constexpr Domain exclude_list_domain("exclude_list");
bool bool
ExcludeList::LoadFile(const Path &path_fs) ExcludeList::LoadFile(const Path &path_fs)
{ {
FILE *file = FOpen(path_fs, FOpenMode::ReadText); FILE *file = FOpen(path_fs, FOpenMode::ReadText);
if (file == NULL) { if (file == NULL) {
if (errno != ENOENT) { const int e = errno;
const char *msg = g_strerror(errno); if (e != ENOENT) {
const auto path_utf8 = path_fs.ToUTF8(); const auto path_utf8 = path_fs.ToUTF8();
g_debug("Failed to open %s: %s", FormatErrno(exclude_list_domain,
path_utf8.c_str(), msg); "Failed to open %s",
path_utf8.c_str());
} }
return false; return false;
......
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include <assert.h> #include <assert.h>
#include <glib.h> #include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "global_events"
namespace GlobalEvents { namespace GlobalEvents {
class Monitor final : public DeferredMonitor { class Monitor final : public DeferredMonitor {
public: public:
......
...@@ -20,14 +20,15 @@ ...@@ -20,14 +20,15 @@
#include "config.h" #include "config.h"
#include "IcyMetaDataParser.hxx" #include "IcyMetaDataParser.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain icy_metadata_domain("icy_metadata");
#define G_LOG_DOMAIN "icy_metadata"
void void
IcyMetaDataParser::Reset() IcyMetaDataParser::Reset()
...@@ -88,7 +89,8 @@ icy_parse_tag_item(Tag &tag, const char *item) ...@@ -88,7 +89,8 @@ icy_parse_tag_item(Tag &tag, const char *item)
if (strcmp(p[0], "StreamTitle") == 0) if (strcmp(p[0], "StreamTitle") == 0)
icy_add_item(tag, TAG_TITLE, p[1]); icy_add_item(tag, TAG_TITLE, p[1]);
else else
g_debug("unknown icy-tag: '%s'", p[0]); FormatDebug(icy_metadata_domain,
"unknown icy-tag: '%s'", p[0]);
} }
g_strfreev(p); g_strfreev(p);
......
...@@ -27,9 +27,6 @@ ...@@ -27,9 +27,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "icy_server"
char* char*
icy_server_metadata_header(const char *name, icy_server_metadata_header(const char *name,
const char *genre, const char *url, const char *genre, const char *url,
......
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "InotifyDomain.hxx"
#include "util/Domain.hxx"
const Domain inotify_domain("inotify");
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_INOTIFY_DOMAIN_HXX
#define MPD_INOTIFY_DOMAIN_HXX
extern const class Domain inotify_domain;
#endif
...@@ -19,16 +19,13 @@ ...@@ -19,16 +19,13 @@
#include "config.h" #include "config.h"
#include "InotifyQueue.hxx" #include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "UpdateGlue.hxx" #include "UpdateGlue.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "Log.hxx"
#include <glib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
enum { enum {
/** /**
* Wait this long after the last change before calling * Wait this long after the last change before calling
...@@ -53,7 +50,8 @@ InotifyQueue::OnTimeout() ...@@ -53,7 +50,8 @@ InotifyQueue::OnTimeout()
return; return;
} }
g_debug("updating '%s' job=%u", uri_utf8, id); FormatDebug(inotify_domain, "updating '%s' job=%u",
uri_utf8, id);
queue.pop_front(); queue.pop_front();
} }
......
...@@ -19,19 +19,17 @@ ...@@ -19,19 +19,17 @@
#include "config.h" #include "config.h"
#include "InotifySource.hxx" #include "InotifySource.hxx"
#include "InotifyDomain.hxx"
#include "util/fifo_buffer.h" #include "util/fifo_buffer.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "system/fd_util.h" #include "system/fd_util.h"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
bool bool
InotifySource::OnSocketReady(gcc_unused unsigned flags) InotifySource::OnSocketReady(gcc_unused unsigned flags)
...@@ -120,8 +118,7 @@ InotifySource::Remove(unsigned wd) ...@@ -120,8 +118,7 @@ InotifySource::Remove(unsigned wd)
{ {
int ret = inotify_rm_watch(Get(), wd); int ret = inotify_rm_watch(Get(), wd);
if (ret < 0 && errno != EINVAL) if (ret < 0 && errno != EINVAL)
g_warning("inotify_rm_watch() has failed: %s", LogErrno(inotify_domain, "inotify_rm_watch() has failed");
g_strerror(errno));
/* EINVAL may happen here when the file has been deleted; the /* EINVAL may happen here when the file has been deleted; the
kernel seems to auto-unregister deleted files */ kernel seems to auto-unregister deleted files */
......
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
#include "InotifyUpdate.hxx" #include "InotifyUpdate.hxx"
#include "InotifySource.hxx" #include "InotifySource.hxx"
#include "InotifyQueue.hxx" #include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -36,10 +38,6 @@ ...@@ -36,10 +38,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
enum { enum {
IN_MASK = IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF IN_MASK = IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF
...@@ -120,7 +118,8 @@ remove_watch_directory(WatchDirectory *directory) ...@@ -120,7 +118,8 @@ remove_watch_directory(WatchDirectory *directory)
assert(directory != NULL); assert(directory != NULL);
if (directory->parent == NULL) { if (directory->parent == NULL) {
g_warning("music directory was removed - " LogWarning(inotify_domain,
"music directory was removed - "
"cannot continue to watch it"); "cannot continue to watch it");
return; return;
} }
...@@ -178,8 +177,8 @@ recursive_watch_subdirectories(WatchDirectory *directory, ...@@ -178,8 +177,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
dir = opendir(path_fs); dir = opendir(path_fs);
if (dir == NULL) { if (dir == NULL) {
g_warning("Failed to open directory %s: %s", FormatErrno(inotify_domain,
path_fs, g_strerror(errno)); "Failed to open directory %s", path_fs);
return; return;
} }
...@@ -194,8 +193,9 @@ recursive_watch_subdirectories(WatchDirectory *directory, ...@@ -194,8 +193,9 @@ recursive_watch_subdirectories(WatchDirectory *directory,
child_path_fs = g_strconcat(path_fs, "/", ent->d_name, NULL); child_path_fs = g_strconcat(path_fs, "/", ent->d_name, NULL);
ret = stat(child_path_fs, &st); ret = stat(child_path_fs, &st);
if (ret < 0) { if (ret < 0) {
g_warning("Failed to stat %s: %s", FormatErrno(inotify_domain,
child_path_fs, g_strerror(errno)); "Failed to stat %s",
child_path_fs);
g_free(child_path_fs); g_free(child_path_fs);
continue; continue;
} }
...@@ -207,8 +207,8 @@ recursive_watch_subdirectories(WatchDirectory *directory, ...@@ -207,8 +207,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
ret = inotify_source->Add(child_path_fs, IN_MASK, error); ret = inotify_source->Add(child_path_fs, IN_MASK, error);
if (ret < 0) { if (ret < 0) {
g_warning("Failed to register %s: %s", FormatError(error,
child_path_fs, error.GetMessage()); "Failed to register %s", child_path_fs);
error.Clear(); error.Clear();
g_free(child_path_fs); g_free(child_path_fs);
continue; continue;
...@@ -253,7 +253,7 @@ mpd_inotify_callback(int wd, unsigned mask, ...@@ -253,7 +253,7 @@ mpd_inotify_callback(int wd, unsigned mask,
WatchDirectory *directory; WatchDirectory *directory;
char *uri_fs; char *uri_fs;
/*g_debug("wd=%d mask=0x%x name='%s'", wd, mask, name);*/ /*FormatDebug(inotify_domain, "wd=%d mask=0x%x name='%s'", wd, mask, name);*/
directory = tree_find_watch_directory(wd); directory = tree_find_watch_directory(wd);
if (directory == NULL) if (directory == NULL)
...@@ -309,11 +309,11 @@ mpd_inotify_callback(int wd, unsigned mask, ...@@ -309,11 +309,11 @@ mpd_inotify_callback(int wd, unsigned mask,
void void
mpd_inotify_init(unsigned max_depth) mpd_inotify_init(unsigned max_depth)
{ {
g_debug("initializing inotify"); LogDebug(inotify_domain, "initializing inotify");
const Path &path = mapper_get_music_directory_fs(); const Path &path = mapper_get_music_directory_fs();
if (path.IsNull()) { if (path.IsNull()) {
g_debug("no music directory configured"); LogDebug(inotify_domain, "no music directory configured");
return; return;
} }
...@@ -322,7 +322,7 @@ mpd_inotify_init(unsigned max_depth) ...@@ -322,7 +322,7 @@ mpd_inotify_init(unsigned max_depth)
mpd_inotify_callback, nullptr, mpd_inotify_callback, nullptr,
error); error);
if (inotify_source == NULL) { if (inotify_source == NULL) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
...@@ -330,7 +330,7 @@ mpd_inotify_init(unsigned max_depth) ...@@ -330,7 +330,7 @@ mpd_inotify_init(unsigned max_depth)
int descriptor = inotify_source->Add(path.c_str(), IN_MASK, error); int descriptor = inotify_source->Add(path.c_str(), IN_MASK, error);
if (descriptor < 0) { if (descriptor < 0) {
g_warning("%s", error.GetMessage()); LogError(error);
delete inotify_source; delete inotify_source;
inotify_source = NULL; inotify_source = NULL;
return; return;
...@@ -344,7 +344,7 @@ mpd_inotify_init(unsigned max_depth) ...@@ -344,7 +344,7 @@ mpd_inotify_init(unsigned max_depth)
inotify_queue = new InotifyQueue(*main_loop); inotify_queue = new InotifyQueue(*main_loop);
g_debug("watching music directory"); LogDebug(inotify_domain, "watching music directory");
} }
void void
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
#include "ConfigOption.hxx" #include "ConfigOption.hxx"
#include "event/ServerSocket.hxx" #include "event/ServerSocket.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -38,8 +40,7 @@ ...@@ -38,8 +40,7 @@
#include <systemd/sd-daemon.h> #include <systemd/sd-daemon.h>
#endif #endif
#undef G_LOG_DOMAIN static constexpr Domain listen_domain("listen");
#define G_LOG_DOMAIN "listen"
#define DEFAULT_PORT 6600 #define DEFAULT_PORT 6600
...@@ -82,8 +83,8 @@ listen_systemd_activation(Error &error_r) ...@@ -82,8 +83,8 @@ listen_systemd_activation(Error &error_r)
int n = sd_listen_fds(true); int n = sd_listen_fds(true);
if (n <= 0) { if (n <= 0) {
if (n < 0) if (n < 0)
g_warning("sd_listen_fds() failed: %s", FormatErrno(listen_domain, -n,
g_strerror(-n)); "sd_listen_fds() failed");
return false; return false;
} }
...@@ -155,7 +156,7 @@ listen_global_init(Error &error) ...@@ -155,7 +156,7 @@ listen_global_init(Error &error)
void listen_global_finish(void) void listen_global_finish(void)
{ {
g_debug("listen_global_finish called"); LogDebug(listen_domain, "listen_global_finish called");
assert(listen_socket != NULL); assert(listen_socket != NULL);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "Log.hxx" #include "LogV.hxx"
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigOption.hxx" #include "ConfigOption.hxx"
...@@ -30,322 +30,157 @@ ...@@ -30,322 +30,157 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <glib.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "log"
#define LOG_LEVEL_SECURE G_LOG_LEVEL_INFO static GLogLevelFlags
ToGLib(LogLevel level)
#define LOG_DATE_BUF_SIZE 16 {
#define LOG_DATE_LEN (LOG_DATE_BUF_SIZE - 1) switch (level) {
case LogLevel::DEBUG:
static constexpr Domain log_domain("log"); return G_LOG_LEVEL_DEBUG;
static GLogLevelFlags log_threshold = G_LOG_LEVEL_MESSAGE;
static const char *log_charset; case LogLevel::INFO:
return G_LOG_LEVEL_MESSAGE;
static bool stdout_mode = true; case LogLevel::WARNING:
static int out_fd; case LogLevel::ERROR:
static Path out_path = Path::Null(); return G_LOG_LEVEL_WARNING;
}
static void redirect_logs(int fd) assert(false);
{ gcc_unreachable();
assert(fd >= 0);
if (dup2(fd, STDOUT_FILENO) < 0)
FatalSystemError("Failed to dup2 stdout");
if (dup2(fd, STDERR_FILENO) < 0)
FatalSystemError("Failed to dup2 stderr");
} }
static const char *log_date(void) void
Log(const Domain &domain, LogLevel level, const char *msg)
{ {
static char buf[LOG_DATE_BUF_SIZE]; g_log(domain.GetName(), ToGLib(level), "%s", msg);
time_t t = time(NULL);
strftime(buf, LOG_DATE_BUF_SIZE, "%b %d %H:%M : ", localtime(&t));
return buf;
} }
/** void
* Determines the length of the string excluding trailing whitespace LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap)
* characters.
*/
static int
chomp_length(const char *p)
{ {
size_t length = strlen(p); g_logv(domain.GetName(), ToGLib(level), fmt, ap);
while (length > 0 && g_ascii_isspace(p[length - 1]))
--length;
return (int)length;
} }
static void void
file_log_func(const gchar *domain, LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{ {
char *converted; va_list ap;
va_start(ap, fmt);
if (log_level > log_threshold) LogFormatV(domain, level, fmt, ap);
return; va_end(ap);
if (log_charset != NULL) {
converted = g_convert_with_fallback(message, -1,
log_charset, "utf-8",
NULL, NULL, NULL, NULL);
if (converted != NULL)
message = converted;
} else
converted = NULL;
if (domain == nullptr)
domain = "";
fprintf(stderr, "%s%s%s%.*s\n",
stdout_mode ? "" : log_date(),
domain, *domain == 0 ? "" : ": ",
chomp_length(message), message);
g_free(converted);
} }
static void void
log_init_stdout(void) FormatDebug(const Domain &domain, const char *fmt, ...)
{ {
g_log_set_default_handler(file_log_func, NULL); va_list ap;
va_start(ap, fmt);
LogFormatV(domain, LogLevel::DEBUG, fmt, ap);
va_end(ap);
} }
static int void
open_log_file(void) FormatInfo(const Domain &domain, const char *fmt, ...)
{ {
assert(!out_path.IsNull()); va_list ap;
va_start(ap, fmt);
return OpenFile(out_path, O_CREAT | O_WRONLY | O_APPEND, 0666); LogFormatV(domain, LogLevel::INFO, fmt, ap);
va_end(ap);
} }
static bool void
log_init_file(unsigned line, Error &error) FormatWarning(const Domain &domain, const char *fmt, ...)
{ {
assert(!out_path.IsNull()); va_list ap;
va_start(ap, fmt);
out_fd = open_log_file(); LogFormatV(domain, LogLevel::WARNING, fmt, ap);
if (out_fd < 0) { va_end(ap);
const std::string out_path_utf8 = out_path.ToUTF8();
error.FormatErrno("failed to open log file \"%s\" (config line %u)",
out_path_utf8.c_str(), line);
return false;
}
g_log_set_default_handler(file_log_func, NULL);
return true;
} }
#ifdef HAVE_SYSLOG void
FormatError(const Domain &domain, const char *fmt, ...)
static int
glib_to_syslog_level(GLogLevelFlags log_level)
{ {
switch (log_level & G_LOG_LEVEL_MASK) { va_list ap;
case G_LOG_LEVEL_ERROR: va_start(ap, fmt);
case G_LOG_LEVEL_CRITICAL: LogFormatV(domain, LogLevel::ERROR, fmt, ap);
return LOG_ERR; va_end(ap);
case G_LOG_LEVEL_WARNING:
return LOG_WARNING;
case G_LOG_LEVEL_MESSAGE:
return LOG_NOTICE;
case G_LOG_LEVEL_INFO:
return LOG_INFO;
case G_LOG_LEVEL_DEBUG:
return LOG_DEBUG;
default:
return LOG_NOTICE;
}
} }
static void void
syslog_log_func(const gchar *domain, LogError(const Error &error)
GLogLevelFlags log_level, const gchar *message,
gcc_unused gpointer user_data)
{ {
if (stdout_mode) { Log(error.GetDomain(), LogLevel::ERROR, error.GetMessage());
/* fall back to the file log function during
startup */
file_log_func(domain, log_level,
message, user_data);
return;
}
if (log_level > log_threshold)
return;
if (domain == nullptr)
domain = "";
syslog(glib_to_syslog_level(log_level), "%s%s%.*s",
domain, *domain == 0 ? "" : ": ",
chomp_length(message), message);
} }
static void void
log_init_syslog(void) LogError(const Error &error, const char *msg)
{ {
assert(out_path.IsNull()); LogFormat(error.GetDomain(), LogLevel::ERROR, "%s: %s",
msg, error.GetMessage());
openlog(PACKAGE, 0, LOG_DAEMON);
g_log_set_default_handler(syslog_log_func, NULL);
} }
#endif void
FormatError(const Error &error, const char *fmt, ...)
static inline GLogLevelFlags
parse_log_level(const char *value, unsigned line)
{ {
if (0 == strcmp(value, "default")) char msg[1024];
return G_LOG_LEVEL_MESSAGE; va_list ap;
if (0 == strcmp(value, "secure")) va_start(ap, fmt);
return LOG_LEVEL_SECURE; vsnprintf(msg, sizeof(msg), fmt, ap);
else if (0 == strcmp(value, "verbose")) va_end(ap);
return G_LOG_LEVEL_DEBUG;
else { LogError(error, msg);
FormatFatalError("unknown log level \"%s\" at line %u",
value, line);
return G_LOG_LEVEL_MESSAGE;
}
} }
void void
log_early_init(bool verbose) LogErrno(const Domain &domain, int e, const char *msg)
{ {
if (verbose) LogFormat(domain, LogLevel::ERROR, "%s: %s", msg, g_strerror(e));
log_threshold = G_LOG_LEVEL_DEBUG;
log_init_stdout();
} }
bool void
log_init(bool verbose, bool use_stdout, Error &error) LogErrno(const Domain &domain, const char *msg)
{ {
const struct config_param *param; LogErrno(domain, errno, msg);
g_get_charset(&log_charset);
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
log_threshold = parse_log_level(param->value, param->line);
if (use_stdout) {
log_init_stdout();
return true;
} else {
param = config_get_param(CONF_LOG_FILE);
if (param == NULL) {
#ifdef HAVE_SYSLOG
/* no configuration: default to syslog (if
available) */
log_init_syslog();
return true;
#else
error.Set(log_domain,
"config parameter 'log_file' not found");
return false;
#endif
#ifdef HAVE_SYSLOG
} else if (strcmp(param->value, "syslog") == 0) {
log_init_syslog();
return true;
#endif
} else {
out_path = config_get_path(CONF_LOG_FILE, error);
return !out_path.IsNull() &&
log_init_file(param->line, error);
}
}
} }
static void static void
close_log_files(void) FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap)
{ {
if (stdout_mode) char msg[1024];
return; vsnprintf(msg, sizeof(msg), fmt, ap);
#ifdef HAVE_SYSLOG LogErrno(domain, e, msg);
if (out_path.IsNull())
closelog();
#endif
} }
void void
log_deinit(void) FormatErrno(const Domain &domain, int e, const char *fmt, ...)
{ {
close_log_files(); va_list ap;
out_path = Path::Null(); va_start(ap, fmt);
FormatErrnoV(domain, e, fmt, ap);
va_end(ap);
} }
void
void setup_log_output(bool use_stdout) FormatErrno(const Domain &domain, const char *fmt, ...)
{
fflush(NULL);
if (!use_stdout) {
#ifndef WIN32
if (out_path.IsNull())
out_fd = open("/dev/null", O_WRONLY);
#endif
if (out_fd >= 0) {
redirect_logs(out_fd);
close(out_fd);
}
stdout_mode = false;
log_charset = NULL;
}
}
int cycle_log_files(void)
{ {
int fd; const int e = errno;
if (stdout_mode || out_path.IsNull())
return 0;
assert(!out_path.IsNull());
g_debug("Cycling log files...\n");
close_log_files();
fd = open_log_file();
if (fd < 0) {
const std::string out_path_utf8 = out_path.ToUTF8();
g_warning("error re-opening log file: %s",
out_path_utf8.c_str());
return -1;
}
redirect_logs(fd); va_list ap;
g_debug("Done cycling log files\n"); va_start(ap, fmt);
return 0; FormatErrnoV(domain, e, fmt, ap);
va_end(ap);
} }
...@@ -20,27 +20,95 @@ ...@@ -20,27 +20,95 @@
#ifndef MPD_LOG_HXX #ifndef MPD_LOG_HXX
#define MPD_LOG_HXX #define MPD_LOG_HXX
#include "gcc.h"
#ifdef WIN32
#include <windows.h>
/* damn you, windows.h! */
#ifdef ERROR
#undef ERROR
#endif
#endif
class Error; class Error;
class Domain;
enum class LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
};
void
Log(const Domain &domain, LogLevel level, const char *msg);
gcc_fprintf_
void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...);
static inline void
LogDebug(const Domain &domain, const char *msg)
{
Log(domain, LogLevel::DEBUG, msg);
}
gcc_fprintf
void
FormatDebug(const Domain &domain, const char *fmt, ...);
static inline void
LogInfo(const Domain &domain, const char *msg)
{
Log(domain, LogLevel::INFO, msg);
}
gcc_fprintf
void
FormatInfo(const Domain &domain, const char *fmt, ...);
static inline void
LogWarning(const Domain &domain, const char *msg)
{
Log(domain, LogLevel::WARNING, msg);
}
gcc_fprintf
void
FormatWarning(const Domain &domain, const char *fmt, ...);
static inline void
LogError(const Domain &domain, const char *msg)
{
Log(domain, LogLevel::ERROR, msg);
}
gcc_fprintf
void
FormatError(const Domain &domain, const char *fmt, ...);
/**
* Configure a logging destination for daemon startup, before the
* configuration file is read. This allows the daemon to use the
* logging library (and the command line verbose level) before it's
* daemonized.
*
* @param verbose true when the program is started with --verbose
*/
void void
log_early_init(bool verbose); LogError(const Error &error);
bool void
log_init(bool verbose, bool use_stdout, Error &error); LogError(const Error &error, const char *msg);
gcc_fprintf
void
FormatError(const Error &error, const char *fmt, ...);
void void
log_deinit(void); LogErrno(const Domain &domain, int e, const char *msg);
void setup_log_output(bool use_stdout); void
LogErrno(const Domain &domain, const char *msg);
int cycle_log_files(void); gcc_fprintf_
void
FormatErrno(const Domain &domain, int e, const char *fmt, ...);
gcc_fprintf
void
FormatErrno(const Domain &domain, const char *fmt, ...);
#endif /* LOG_H */ #endif /* LOG_H */
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "config.h"
#include "LogInit.hxx"
#include "Log.hxx"
#include "ConfigData.hxx"
#include "ConfigGlobal.hxx"
#include "ConfigOption.hxx"
#include "system/fd_util.h"
#include "system/FatalError.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "system/FatalError.hxx"
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <glib.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
#define LOG_LEVEL_SECURE G_LOG_LEVEL_INFO
#define LOG_DATE_BUF_SIZE 16
#define LOG_DATE_LEN (LOG_DATE_BUF_SIZE - 1)
static constexpr Domain log_domain("log");
static GLogLevelFlags log_threshold = G_LOG_LEVEL_MESSAGE;
static const char *log_charset;
static bool stdout_mode = true;
static int out_fd;
static Path out_path = Path::Null();
static void redirect_logs(int fd)
{
assert(fd >= 0);
if (dup2(fd, STDOUT_FILENO) < 0)
FatalSystemError("Failed to dup2 stdout");
if (dup2(fd, STDERR_FILENO) < 0)
FatalSystemError("Failed to dup2 stderr");
}
static const char *log_date(void)
{
static char buf[LOG_DATE_BUF_SIZE];
time_t t = time(NULL);
strftime(buf, LOG_DATE_BUF_SIZE, "%b %d %H:%M : ", localtime(&t));
return buf;
}
/**
* Determines the length of the string excluding trailing whitespace
* characters.
*/
static int
chomp_length(const char *p)
{
size_t length = strlen(p);
while (length > 0 && g_ascii_isspace(p[length - 1]))
--length;
return (int)length;
}
static void
file_log_func(const gchar *domain,
GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{
char *converted;
if (log_level > log_threshold)
return;
if (log_charset != NULL) {
converted = g_convert_with_fallback(message, -1,
log_charset, "utf-8",
NULL, NULL, NULL, NULL);
if (converted != NULL)
message = converted;
} else
converted = NULL;
if (domain == nullptr)
domain = "";
fprintf(stderr, "%s%s%s%.*s\n",
stdout_mode ? "" : log_date(),
domain, *domain == 0 ? "" : ": ",
chomp_length(message), message);
g_free(converted);
}
static void
log_init_stdout(void)
{
g_log_set_default_handler(file_log_func, NULL);
}
static int
open_log_file(void)
{
assert(!out_path.IsNull());
return OpenFile(out_path, O_CREAT | O_WRONLY | O_APPEND, 0666);
}
static bool
log_init_file(unsigned line, Error &error)
{
assert(!out_path.IsNull());
out_fd = open_log_file();
if (out_fd < 0) {
const std::string out_path_utf8 = out_path.ToUTF8();
error.FormatErrno("failed to open log file \"%s\" (config line %u)",
out_path_utf8.c_str(), line);
return false;
}
g_log_set_default_handler(file_log_func, NULL);
return true;
}
#ifdef HAVE_SYSLOG
static int
glib_to_syslog_level(GLogLevelFlags log_level)
{
switch (log_level & G_LOG_LEVEL_MASK) {
case G_LOG_LEVEL_ERROR:
case G_LOG_LEVEL_CRITICAL:
return LOG_ERR;
case G_LOG_LEVEL_WARNING:
return LOG_WARNING;
case G_LOG_LEVEL_MESSAGE:
return LOG_NOTICE;
case G_LOG_LEVEL_INFO:
return LOG_INFO;
case G_LOG_LEVEL_DEBUG:
return LOG_DEBUG;
default:
return LOG_NOTICE;
}
}
static void
syslog_log_func(const gchar *domain,
GLogLevelFlags log_level, const gchar *message,
gcc_unused gpointer user_data)
{
if (stdout_mode) {
/* fall back to the file log function during
startup */
file_log_func(domain, log_level,
message, user_data);
return;
}
if (log_level > log_threshold)
return;
if (domain == nullptr)
domain = "";
syslog(glib_to_syslog_level(log_level), "%s%s%.*s",
domain, *domain == 0 ? "" : ": ",
chomp_length(message), message);
}
static void
log_init_syslog(void)
{
assert(out_path.IsNull());
openlog(PACKAGE, 0, LOG_DAEMON);
g_log_set_default_handler(syslog_log_func, NULL);
}
#endif
static inline GLogLevelFlags
parse_log_level(const char *value, unsigned line)
{
if (0 == strcmp(value, "default"))
return G_LOG_LEVEL_MESSAGE;
if (0 == strcmp(value, "secure"))
return LOG_LEVEL_SECURE;
else if (0 == strcmp(value, "verbose"))
return G_LOG_LEVEL_DEBUG;
else {
FormatFatalError("unknown log level \"%s\" at line %u",
value, line);
return G_LOG_LEVEL_MESSAGE;
}
}
void
log_early_init(bool verbose)
{
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
log_init_stdout();
}
bool
log_init(bool verbose, bool use_stdout, Error &error)
{
const struct config_param *param;
g_get_charset(&log_charset);
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
log_threshold = parse_log_level(param->value, param->line);
if (use_stdout) {
log_init_stdout();
return true;
} else {
param = config_get_param(CONF_LOG_FILE);
if (param == NULL) {
#ifdef HAVE_SYSLOG
/* no configuration: default to syslog (if
available) */
log_init_syslog();
return true;
#else
error.Set(log_domain,
"config parameter 'log_file' not found");
return false;
#endif
#ifdef HAVE_SYSLOG
} else if (strcmp(param->value, "syslog") == 0) {
log_init_syslog();
return true;
#endif
} else {
out_path = config_get_path(CONF_LOG_FILE, error);
return !out_path.IsNull() &&
log_init_file(param->line, error);
}
}
}
static void
close_log_files(void)
{
if (stdout_mode)
return;
#ifdef HAVE_SYSLOG
if (out_path.IsNull())
closelog();
#endif
}
void
log_deinit(void)
{
close_log_files();
out_path = Path::Null();
}
void setup_log_output(bool use_stdout)
{
fflush(NULL);
if (!use_stdout) {
#ifndef WIN32
if (out_path.IsNull())
out_fd = open("/dev/null", O_WRONLY);
#endif
if (out_fd >= 0) {
redirect_logs(out_fd);
close(out_fd);
}
stdout_mode = false;
log_charset = NULL;
}
}
int cycle_log_files(void)
{
int fd;
if (stdout_mode || out_path.IsNull())
return 0;
assert(!out_path.IsNull());
FormatDebug(log_domain, "Cycling log files");
close_log_files();
fd = open_log_file();
if (fd < 0) {
const std::string out_path_utf8 = out_path.ToUTF8();
FormatError(log_domain,
"error re-opening log file: %s",
out_path_utf8.c_str());
return -1;
}
redirect_logs(fd);
FormatDebug(log_domain, "Done cycling log files");
return 0;
}
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_LOG_INIT_HXX
#define MPD_LOG_INIT_HXX
class Error;
/**
* Configure a logging destination for daemon startup, before the
* configuration file is read. This allows the daemon to use the
* logging library (and the command line verbose level) before it's
* daemonized.
*
* @param verbose true when the program is started with --verbose
*/
void
log_early_init(bool verbose);
bool
log_init(bool verbose, bool use_stdout, Error &error);
void
log_deinit(void);
void setup_log_output(bool use_stdout);
int cycle_log_files(void);
#endif /* LOG_H */
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_LOGV_HXX
#define MPD_LOGV_HXX
#include "Log.hxx"
#include <stdarg.h>
void
LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap);
#endif /* LOG_H */
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "Idle.hxx" #include "Idle.hxx"
#include "SignalHandlers.hxx" #include "SignalHandlers.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "LogInit.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "InputInit.hxx" #include "InputInit.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
#include "Daemon.hxx" #include "Daemon.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "ConfigDefaults.hxx" #include "ConfigDefaults.hxx"
...@@ -98,6 +100,8 @@ enum { ...@@ -98,6 +100,8 @@ enum {
DEFAULT_BUFFER_BEFORE_PLAY = 10, DEFAULT_BUFFER_BEFORE_PLAY = 10,
}; };
static constexpr Domain main_domain("main");
GThread *main_task; GThread *main_task;
EventLoop *main_loop; EventLoop *main_loop;
...@@ -105,11 +109,6 @@ Instance *instance; ...@@ -105,11 +109,6 @@ Instance *instance;
static StateFile *state_file; static StateFile *state_file;
static inline GQuark main_quark()
{
return g_quark_from_static_string ("main");
}
static bool static bool
glue_daemonize_init(const struct options *options, Error &error) glue_daemonize_init(const struct options *options, Error &error)
{ {
...@@ -161,14 +160,17 @@ glue_db_init_and_load(void) ...@@ -161,14 +160,17 @@ glue_db_init_and_load(void)
const struct config_param *path = config_get_param(CONF_DB_FILE); const struct config_param *path = config_get_param(CONF_DB_FILE);
if (param != nullptr && path != nullptr) if (param != nullptr && path != nullptr)
g_message("Found both 'database' and 'db_file' setting - ignoring the latter"); LogInfo(main_domain,
"Found both 'database' and 'db_file' setting - ignoring the latter");
if (!mapper_has_music_directory()) { if (!mapper_has_music_directory()) {
if (param != nullptr) if (param != nullptr)
g_message("Found database setting without " LogInfo(main_domain,
"Found database setting without "
"music_directory - disabling database"); "music_directory - disabling database");
if (path != nullptr) if (path != nullptr)
g_message("Found db_file setting without " LogInfo(main_domain,
"Found db_file setting without "
"music_directory - disabling database"); "music_directory - disabling database");
return true; return true;
} }
...@@ -372,12 +374,12 @@ int mpd_main(int argc, char *argv[]) ...@@ -372,12 +374,12 @@ int mpd_main(int argc, char *argv[])
success = parse_cmdline(argc, argv, &options, error); success = parse_cmdline(argc, argv, &options, error);
if (!success) { if (!success) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!glue_daemonize_init(&options, error)) { if (!glue_daemonize_init(&options, error)) {
g_printerr("%s\n", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -385,7 +387,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -385,7 +387,7 @@ int mpd_main(int argc, char *argv[])
TagLoadConfig(); TagLoadConfig();
if (!log_init(options.verbose, options.log_stderr, error)) { if (!log_init(options.verbose, options.log_stderr, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -399,7 +401,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -399,7 +401,7 @@ int mpd_main(int argc, char *argv[])
success = listen_global_init(error); success = listen_global_init(error);
if (!success) { if (!success) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -414,7 +416,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -414,7 +416,7 @@ int mpd_main(int argc, char *argv[])
Path::GlobalInit(); Path::GlobalInit();
if (!glue_mapper_init(error)) { if (!glue_mapper_init(error)) {
g_printerr("%s\n", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -426,7 +428,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -426,7 +428,7 @@ int mpd_main(int argc, char *argv[])
#endif #endif
if (!pcm_resample_global_init(error)) { if (!pcm_resample_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -446,7 +448,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -446,7 +448,7 @@ int mpd_main(int argc, char *argv[])
replay_gain_global_init(); replay_gain_global_init();
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -486,7 +488,8 @@ int mpd_main(int argc, char *argv[]) ...@@ -486,7 +488,8 @@ int mpd_main(int argc, char *argv[])
G_MAXUINT)); G_MAXUINT));
#else #else
if (success) if (success)
g_warning("inotify: auto_update was disabled. enable during compilation phase"); FormatWarning(main_domain,
"inotify: auto_update was disabled. enable during compilation phase");
#endif #endif
config_global_check(); config_global_check();
...@@ -524,7 +527,8 @@ int mpd_main(int argc, char *argv[]) ...@@ -524,7 +527,8 @@ int mpd_main(int argc, char *argv[])
start = clock(); start = clock();
DatabaseGlobalDeinit(); DatabaseGlobalDeinit();
g_debug("db_finish took %f seconds", FormatDebug(main_domain,
"db_finish took %f seconds",
((float)(clock()-start))/CLOCKS_PER_SEC); ((float)(clock()-start))/CLOCKS_PER_SEC);
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx" #include "fs/DirectoryReader.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -38,6 +40,8 @@ ...@@ -38,6 +40,8 @@
#include <errno.h> #include <errno.h>
#include <dirent.h> #include <dirent.h>
static constexpr Domain mapper_domain("mapper");
/** /**
* The absolute path of the music directory encoded in UTF-8. * The absolute path of the music directory encoded in UTF-8.
*/ */
...@@ -57,12 +61,6 @@ static size_t music_dir_fs_length; ...@@ -57,12 +61,6 @@ static size_t music_dir_fs_length;
*/ */
static Path playlist_dir_fs = Path::Null(); static Path playlist_dir_fs = Path::Null();
static inline GQuark
mapper_quark()
{
return g_quark_from_static_string ("mapper");
}
/** /**
* Duplicate a string, chop all trailing slashes. * Duplicate a string, chop all trailing slashes.
*/ */
...@@ -82,26 +80,30 @@ check_directory(const char *path_utf8, const Path &path_fs) ...@@ -82,26 +80,30 @@ check_directory(const char *path_utf8, const Path &path_fs)
{ {
struct stat st; struct stat st;
if (!StatFile(path_fs, st)) { if (!StatFile(path_fs, st)) {
g_warning("Failed to stat directory \"%s\": %s", FormatErrno(mapper_domain,
path_utf8, g_strerror(errno)); "Failed to stat directory \"%s\"",
path_utf8);
return; return;
} }
if (!S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode)) {
g_warning("Not a directory: %s", path_utf8); FormatError(mapper_domain,
"Not a directory: %s", path_utf8);
return; return;
} }
#ifndef WIN32 #ifndef WIN32
const Path x = Path::Build(path_fs, "."); const Path x = Path::Build(path_fs, ".");
if (!StatFile(x, st) && errno == EACCES) if (!StatFile(x, st) && errno == EACCES)
g_warning("No permission to traverse (\"execute\") directory: %s", FormatError(mapper_domain,
"No permission to traverse (\"execute\") directory: %s",
path_utf8); path_utf8);
#endif #endif
const DirectoryReader reader(path_fs); const DirectoryReader reader(path_fs);
if (reader.HasFailed() && errno == EACCES) if (reader.HasFailed() && errno == EACCES)
g_warning("No permission to read directory: %s", path_utf8); FormatError(mapper_domain,
"No permission to read directory: %s", path_utf8);
} }
static void static void
......
...@@ -26,13 +26,12 @@ ...@@ -26,13 +26,12 @@
#include "pcm/PcmVolume.hxx" #include "pcm/PcmVolume.hxx"
#include "OutputInternal.hxx" #include "OutputInternal.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include <glib.h> #include "Log.hxx"
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN static constexpr Domain mixer_domain("mixer");
#define G_LOG_DOMAIN "mixer"
static int static int
output_mixer_get_volume(unsigned i) output_mixer_get_volume(unsigned i)
...@@ -53,8 +52,9 @@ output_mixer_get_volume(unsigned i) ...@@ -53,8 +52,9 @@ output_mixer_get_volume(unsigned i)
Error error; Error error;
volume = mixer_get_volume(mixer, error); volume = mixer_get_volume(mixer, error);
if (volume < 0 && error.IsDefined()) if (volume < 0 && error.IsDefined())
g_warning("Failed to read mixer for '%s': %s", FormatError(error,
output->name, error.GetMessage()); "Failed to read mixer for '%s'",
output->name);
return volume; return volume;
} }
...@@ -99,8 +99,9 @@ output_mixer_set_volume(unsigned i, unsigned volume) ...@@ -99,8 +99,9 @@ output_mixer_set_volume(unsigned i, unsigned volume)
Error error; Error error;
success = mixer_set_volume(mixer, volume, error); success = mixer_set_volume(mixer, volume, error);
if (!success && error.IsDefined()) if (!success && error.IsDefined())
g_warning("Failed to set mixer for '%s': %s", FormatError(error,
output->name, error.GetMessage()); "Failed to set mixer for '%s'",
output->name);
return success; return success;
} }
......
...@@ -25,9 +25,6 @@ ...@@ -25,9 +25,6 @@
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mixer"
Mixer * Mixer *
mixer_new(const struct mixer_plugin *plugin, void *ao, mixer_new(const struct mixer_plugin *plugin, void *ao,
const config_param &param, const config_param &param,
......
...@@ -36,9 +36,6 @@ ...@@ -36,9 +36,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "output"
static AudioFormat input_audio_format; static AudioFormat input_audio_format;
static struct audio_output **audio_outputs; static struct audio_output **audio_outputs;
......
...@@ -22,12 +22,14 @@ ...@@ -22,12 +22,14 @@
#include "OutputThread.hxx" #include "OutputThread.hxx"
#include "OutputInternal.hxx" #include "OutputInternal.hxx"
#include "OutputPlugin.hxx" #include "OutputPlugin.hxx"
#include "OutputError.hxx"
#include "MixerPlugin.hxx" #include "MixerPlugin.hxx"
#include "MixerControl.hxx" #include "MixerControl.hxx"
#include "notify.hxx" #include "notify.hxx"
#include "filter/ReplayGainFilterPlugin.hxx" #include "filter/ReplayGainFilterPlugin.hxx"
#include "FilterPlugin.hxx" #include "FilterPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -191,8 +193,9 @@ audio_output_open(struct audio_output *ao, ...@@ -191,8 +193,9 @@ audio_output_open(struct audio_output *ao,
if (open && ao->mixer != NULL) { if (open && ao->mixer != NULL) {
Error error; Error error;
if (!mixer_open(ao->mixer, error)) if (!mixer_open(ao->mixer, error))
g_warning("Failed to open mixer for '%s': %s", FormatWarning(output_domain,
ao->name, error.GetMessage()); "Failed to open mixer for '%s'",
ao->name);
} }
return open; return open;
......
...@@ -37,15 +37,11 @@ ...@@ -37,15 +37,11 @@
#include "ConfigError.hxx" #include "ConfigError.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "output"
#define AUDIO_OUTPUT_TYPE "type" #define AUDIO_OUTPUT_TYPE "type"
#define AUDIO_OUTPUT_NAME "name" #define AUDIO_OUTPUT_NAME "name"
#define AUDIO_OUTPUT_FORMAT "format" #define AUDIO_OUTPUT_FORMAT "format"
...@@ -54,13 +50,14 @@ ...@@ -54,13 +50,14 @@
static const struct audio_output_plugin * static const struct audio_output_plugin *
audio_output_detect(Error &error) audio_output_detect(Error &error)
{ {
g_warning("Attempt to detect audio output device"); LogInfo(output_domain, "Attempt to detect audio output device");
audio_output_plugins_for_each(plugin) { audio_output_plugins_for_each(plugin) {
if (plugin->test_default_device == NULL) if (plugin->test_default_device == NULL)
continue; continue;
g_warning("Attempting to detect a %s audio device", FormatInfo(output_domain,
"Attempting to detect a %s audio device",
plugin->name); plugin->name);
if (ao_plugin_test_default_device(plugin)) if (ao_plugin_test_default_device(plugin))
return plugin; return plugin;
...@@ -201,8 +198,9 @@ ao_base_init(struct audio_output *ao, ...@@ -201,8 +198,9 @@ ao_base_init(struct audio_output *ao,
// It's not really fatal - Part of the filter chain has been set up already // It's not really fatal - Part of the filter chain has been set up already
// and even an empty one will work (if only with unexpected behaviour) // and even an empty one will work (if only with unexpected behaviour)
if (filter_error.IsDefined()) if (filter_error.IsDefined())
g_warning("Failed to initialize filter chain for '%s': %s", FormatError(filter_error,
ao->name, filter_error.GetMessage()); "Failed to initialize filter chain for '%s'",
ao->name);
ao->thread = NULL; ao->thread = NULL;
ao->command = AO_COMMAND_NONE; ao->command = AO_COMMAND_NONE;
...@@ -251,8 +249,9 @@ audio_output_setup(struct audio_output *ao, const config_param &param, ...@@ -251,8 +249,9 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
ao->plugin->mixer_plugin, ao->plugin->mixer_plugin,
*ao->filter, mixer_error); *ao->filter, mixer_error);
if (ao->mixer == NULL && mixer_error.IsDefined()) if (ao->mixer == NULL && mixer_error.IsDefined())
g_warning("Failed to initialize hardware mixer for '%s': %s", FormatError(mixer_error,
ao->name, mixer_error.GetMessage()); "Failed to initialize hardware mixer for '%s'",
ao->name);
/* use the hardware mixer for replay gain? */ /* use the hardware mixer for replay gain? */
...@@ -261,7 +260,8 @@ audio_output_setup(struct audio_output *ao, const config_param &param, ...@@ -261,7 +260,8 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
replay_gain_filter_set_mixer(ao->replay_gain_filter, replay_gain_filter_set_mixer(ao->replay_gain_filter,
ao->mixer, 100); ao->mixer, 100);
else else
g_warning("No such mixer for output '%s'", ao->name); FormatError(output_domain,
"No such mixer for output '%s'", ao->name);
} else if (strcmp(replay_gain_handler, "software") != 0 && } else if (strcmp(replay_gain_handler, "software") != 0 &&
ao->replay_gain_filter != NULL) { ao->replay_gain_filter != NULL) {
error.Set(config_domain, error.Set(config_domain,
...@@ -304,13 +304,15 @@ audio_output_new(const config_param &param, ...@@ -304,13 +304,15 @@ audio_output_new(const config_param &param,
return nullptr; return nullptr;
} }
} else { } else {
g_warning("No 'audio_output' defined in config file\n"); LogWarning(output_domain,
"No 'audio_output' defined in config file");
plugin = audio_output_detect(error); plugin = audio_output_detect(error);
if (plugin == NULL) if (plugin == NULL)
return nullptr; return nullptr;
g_message("Successfully detected a %s audio device", FormatInfo(output_domain,
"Successfully detected a %s audio device",
plugin->name); plugin->name);
} }
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "OutputState.hxx" #include "OutputState.hxx"
#include "OutputAll.hxx" #include "OutputAll.hxx"
#include "OutputInternal.hxx" #include "OutputInternal.hxx"
#include "OutputError.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -76,7 +78,8 @@ audio_output_state_read(const char *line) ...@@ -76,7 +78,8 @@ audio_output_state_read(const char *line)
name = endptr + 1; name = endptr + 1;
ao = audio_output_find(name); ao = audio_output_find(name);
if (ao == NULL) { if (ao == NULL) {
g_debug("Ignoring device state for '%s'", name); FormatDebug(output_domain,
"Ignoring device state for '%s'", name);
return true; return true;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "OutputThread.hxx" #include "OutputThread.hxx"
#include "OutputInternal.hxx" #include "OutputInternal.hxx"
#include "OutputAPI.hxx" #include "OutputAPI.hxx"
#include "OutputError.hxx"
#include "pcm/PcmMix.hxx" #include "pcm/PcmMix.hxx"
#include "notify.hxx" #include "notify.hxx"
#include "FilterInternal.hxx" #include "FilterInternal.hxx"
...@@ -31,17 +32,13 @@ ...@@ -31,17 +32,13 @@
#include "MusicChunk.hxx" #include "MusicChunk.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include "gcc.h" #include "gcc.h"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "output"
static void ao_command_finished(struct audio_output *ao) static void ao_command_finished(struct audio_output *ao)
{ {
...@@ -66,8 +63,9 @@ ao_enable(struct audio_output *ao) ...@@ -66,8 +63,9 @@ ao_enable(struct audio_output *ao)
success = ao_plugin_enable(ao, error); success = ao_plugin_enable(ao, error);
ao->mutex.lock(); ao->mutex.lock();
if (!success) { if (!success) {
g_warning("Failed to enable \"%s\" [%s]: %s\n", FormatError(error,
ao->name, ao->plugin->name, error.GetMessage()); "Failed to enable \"%s\" [%s]",
ao->name, ao->plugin->name);
return false; return false;
} }
...@@ -159,8 +157,8 @@ ao_open(struct audio_output *ao) ...@@ -159,8 +157,8 @@ ao_open(struct audio_output *ao)
const AudioFormat filter_audio_format = const AudioFormat filter_audio_format =
ao_filter_open(ao, ao->in_audio_format, error); ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) { if (!filter_audio_format.IsDefined()) {
g_warning("Failed to open filter for \"%s\" [%s]: %s", FormatError(error, "Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name, error.GetMessage()); ao->name, ao->plugin->name);
ao->fail_timer = g_timer_new(); ao->fail_timer = g_timer_new();
return; return;
...@@ -178,8 +176,8 @@ ao_open(struct audio_output *ao) ...@@ -178,8 +176,8 @@ ao_open(struct audio_output *ao)
assert(!ao->open); assert(!ao->open);
if (!success) { if (!success) {
g_warning("Failed to open \"%s\" [%s]: %s", FormatError(error, "Failed to open \"%s\" [%s]",
ao->name, ao->plugin->name, error.GetMessage()); ao->name, ao->plugin->name);
ao_filter_close(ao); ao_filter_close(ao);
ao->fail_timer = g_timer_new(); ao->fail_timer = g_timer_new();
...@@ -190,13 +188,13 @@ ao_open(struct audio_output *ao) ...@@ -190,13 +188,13 @@ ao_open(struct audio_output *ao)
ao->open = true; ao->open = true;
g_debug("opened plugin=%s name=\"%s\" " FormatDebug(output_domain,
"audio_format=%s", "opened plugin=%s name=\"%s\" audio_format=%s",
ao->plugin->name, ao->name, ao->plugin->name, ao->name,
audio_format_to_string(ao->out_audio_format, &af_string)); audio_format_to_string(ao->out_audio_format, &af_string));
if (ao->in_audio_format != ao->out_audio_format) if (ao->in_audio_format != ao->out_audio_format)
g_debug("converting from %s", FormatDebug(output_domain, "converting from %s",
audio_format_to_string(ao->in_audio_format, audio_format_to_string(ao->in_audio_format,
&af_string)); &af_string));
} }
...@@ -223,7 +221,8 @@ ao_close(struct audio_output *ao, bool drain) ...@@ -223,7 +221,8 @@ ao_close(struct audio_output *ao, bool drain)
ao->mutex.lock(); ao->mutex.lock();
g_debug("closed plugin=%s name=\"%s\"", ao->plugin->name, ao->name); FormatDebug(output_domain, "closed plugin=%s name=\"%s\"",
ao->plugin->name, ao->name);
} }
static void static void
...@@ -235,8 +234,9 @@ ao_reopen_filter(struct audio_output *ao) ...@@ -235,8 +234,9 @@ ao_reopen_filter(struct audio_output *ao)
const AudioFormat filter_audio_format = const AudioFormat filter_audio_format =
ao_filter_open(ao, ao->in_audio_format, error); ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) { if (!filter_audio_format.IsDefined()) {
g_warning("Failed to open filter for \"%s\" [%s]: %s", FormatError(error,
ao->name, ao->plugin->name, error.GetMessage()); "Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name);
/* this is a little code duplication fro ao_close(), /* this is a little code duplication fro ao_close(),
but we cannot call this function because we must but we cannot call this function because we must
...@@ -334,8 +334,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk, ...@@ -334,8 +334,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk,
data = replay_gain_filter->FilterPCM(data, length, data = replay_gain_filter->FilterPCM(data, length,
&length, error); &length, error);
if (data == NULL) { if (data == NULL) {
g_warning("\"%s\" [%s] failed to filter: %s", FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name, error.GetMessage()); ao->name, ao->plugin->name);
return NULL; return NULL;
} }
} }
...@@ -390,7 +390,8 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk, ...@@ -390,7 +390,8 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
if (!pcm_mix(dest, data, length, if (!pcm_mix(dest, data, length,
ao->in_audio_format.format, ao->in_audio_format.format,
1.0 - chunk->mix_ratio)) { 1.0 - chunk->mix_ratio)) {
g_warning("Cannot cross-fade format %s", FormatError(output_domain,
"Cannot cross-fade format %s",
sample_format_to_string(ao->in_audio_format.format)); sample_format_to_string(ao->in_audio_format.format));
return NULL; return NULL;
} }
...@@ -404,8 +405,8 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk, ...@@ -404,8 +405,8 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
Error error; Error error;
data = ao->filter->FilterPCM(data, length, &length, error); data = ao->filter->FilterPCM(data, length, &length, error);
if (data == NULL) { if (data == NULL) {
g_warning("\"%s\" [%s] failed to filter: %s", FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name, error.GetMessage()); ao->name, ao->plugin->name);
return NULL; return NULL;
} }
...@@ -453,9 +454,8 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk) ...@@ -453,9 +454,8 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk)
ao->mutex.lock(); ao->mutex.lock();
if (nbytes == 0) { if (nbytes == 0) {
/* play()==0 means failure */ /* play()==0 means failure */
g_warning("\"%s\" [%s] failed to play: %s", FormatError(error, "\"%s\" [%s] failed to play",
ao->name, ao->plugin->name, ao->name, ao->plugin->name);
error.GetMessage());
ao_close(ao, false); ao_close(ao, false);
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <cmath> #include <cmath>
...@@ -40,8 +42,7 @@ ...@@ -40,8 +42,7 @@
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain player_domain("player");
#define G_LOG_DOMAIN "player_thread"
enum class CrossFadeState : int8_t { enum class CrossFadeState : int8_t {
DISABLED = -1, DISABLED = -1,
...@@ -402,7 +403,7 @@ Player::OpenOutput() ...@@ -402,7 +403,7 @@ Player::OpenOutput()
return true; return true;
} else { } else {
g_warning("%s", error.GetMessage()); LogError(error);
output_open = false; output_open = false;
...@@ -461,7 +462,8 @@ Player::CheckDecoderStartup() ...@@ -461,7 +462,8 @@ Player::CheckDecoderStartup()
if (!paused && !OpenOutput()) { if (!paused && !OpenOutput()) {
char *uri = dc.song->GetURI(); char *uri = dc.song->GetURI();
g_warning("problems opening audio device " FormatError(player_domain,
"problems opening audio device "
"while playing \"%s\"", uri); "while playing \"%s\"", uri);
g_free(uri); g_free(uri);
...@@ -487,7 +489,7 @@ Player::SendSilence() ...@@ -487,7 +489,7 @@ Player::SendSilence()
struct music_chunk *chunk = buffer.Allocate(); struct music_chunk *chunk = buffer.Allocate();
if (chunk == nullptr) { if (chunk == nullptr) {
g_warning("Failed to allocate silence buffer"); LogError(player_domain, "Failed to allocate silence buffer");
return false; return false;
} }
...@@ -506,7 +508,7 @@ Player::SendSilence() ...@@ -506,7 +508,7 @@ Player::SendSilence()
Error error; Error error;
if (!audio_output_all_play(chunk, error)) { if (!audio_output_all_play(chunk, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
buffer.Return(chunk); buffer.Return(chunk);
return false; return false;
} }
...@@ -838,7 +840,7 @@ Player::PlayNextChunk() ...@@ -838,7 +840,7 @@ Player::PlayNextChunk()
Error error; Error error;
if (!play_chunk(pc, song, chunk, buffer, play_audio_format, error)) { if (!play_chunk(pc, song, chunk, buffer, play_audio_format, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
buffer.Return(chunk); buffer.Return(chunk);
...@@ -877,7 +879,7 @@ Player::SongBorder() ...@@ -877,7 +879,7 @@ Player::SongBorder()
xfade_state = CrossFadeState::UNKNOWN; xfade_state = CrossFadeState::UNKNOWN;
char *uri = song->GetURI(); char *uri = song->GetURI();
g_message("played \"%s\"", uri); FormatInfo(player_domain, "played \"%s\"", uri);
g_free(uri); g_free(uri);
ReplacePipe(dc.pipe); ReplacePipe(dc.pipe);
......
...@@ -19,17 +19,16 @@ ...@@ -19,17 +19,16 @@
#include "config.h" #include "config.h"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx" #include "PlayerControl.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "playlist"
void void
playlist::FullIncrementVersions() playlist::FullIncrementVersions()
{ {
...@@ -65,7 +64,8 @@ playlist_queue_song_order(struct playlist *playlist, struct player_control *pc, ...@@ -65,7 +64,8 @@ playlist_queue_song_order(struct playlist *playlist, struct player_control *pc,
Song *song = playlist->queue.GetOrder(order)->DupDetached(); Song *song = playlist->queue.GetOrder(order)->DupDetached();
uri = song->GetURI(); uri = song->GetURI();
g_debug("queue song %i:\"%s\"", playlist->queued, uri); FormatDebug(playlist_domain, "queue song %i:\"%s\"",
playlist->queued, uri);
g_free(uri); g_free(uri);
pc->EnqueueSong(song); pc->EnqueueSong(song);
...@@ -156,7 +156,7 @@ playlist::PlayOrder(player_control &pc, int order) ...@@ -156,7 +156,7 @@ playlist::PlayOrder(player_control &pc, int order)
Song *song = queue.GetOrder(order)->DupDetached(); Song *song = queue.GetOrder(order)->DupDetached();
char *uri = song->GetURI(); char *uri = song->GetURI();
g_debug("play %i:\"%s\"", order, uri); FormatDebug(playlist_domain, "play %i:\"%s\"", order, uri);
g_free(uri); g_free(uri);
pc.Play(song); pc.Play(song);
......
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistMapper.hxx" #include "PlaylistMapper.hxx"
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "PlaylistError.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
...@@ -43,8 +45,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond, ...@@ -43,8 +45,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
input_stream *is = input_stream::Open(uri, mutex, cond, error); input_stream *is = input_stream::Open(uri, mutex, cond, error);
if (is == nullptr) { if (is == nullptr) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("Failed to open %s: %s", FormatError(error, "Failed to open %s", uri);
uri, error.GetMessage());
return nullptr; return nullptr;
} }
......
...@@ -24,13 +24,10 @@ ...@@ -24,13 +24,10 @@
#include "config.h" #include "config.h"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx" #include "PlayerControl.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Log.hxx"
#include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "playlist"
void void
playlist::Stop(player_control &pc) playlist::Stop(player_control &pc)
...@@ -40,7 +37,7 @@ playlist::Stop(player_control &pc) ...@@ -40,7 +37,7 @@ playlist::Stop(player_control &pc)
assert(current >= 0); assert(current >= 0);
g_debug("stop"); FormatDebug(playlist_domain, "stop");
pc.Stop(); pc.Stop();
queued = -1; queued = -1;
playing = false; playing = false;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "config.h" #include "config.h"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx" #include "PlayerControl.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
#include "Idle.hxx" #include "Idle.hxx"
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
#include "Log.hxx"
#include <stdlib.h> #include <stdlib.h>
...@@ -104,7 +106,7 @@ enum playlist_result ...@@ -104,7 +106,7 @@ enum playlist_result
playlist::AppendURI(struct player_control &pc, playlist::AppendURI(struct player_control &pc,
const char *uri, unsigned *added_id) const char *uri, unsigned *added_id)
{ {
g_debug("add to playlist: %s", uri); FormatDebug(playlist_domain, "add to playlist: %s", uri);
const Database *db = nullptr; const Database *db = nullptr;
Song *song; Song *song;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -321,7 +322,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond, ...@@ -321,7 +322,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
input_stream *is = input_stream::Open(path_fs, mutex, cond, error); input_stream *is = input_stream::Open(path_fs, mutex, cond, error);
if (is == nullptr) { if (is == nullptr) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
return nullptr; return nullptr;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "PlaylistSave.hxx" #include "PlaylistSave.hxx"
#include "PlaylistFile.hxx" #include "PlaylistFile.hxx"
#include "PlaylistError.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -123,7 +125,8 @@ playlist_load_spl(struct playlist *playlist, struct player_control *pc, ...@@ -123,7 +125,8 @@ playlist_load_spl(struct playlist *playlist, struct player_control *pc,
} }
if (playlist->AppendURI(*pc, temp2) != PLAYLIST_RESULT_SUCCESS) if (playlist->AppendURI(*pc, temp2) != PLAYLIST_RESULT_SUCCESS)
g_warning("can't add file \"%s\"", temp2); FormatError(playlist_domain,
"can't add file \"%s\"", temp2);
g_free(temp2); g_free(temp2);
} }
......
...@@ -24,12 +24,14 @@ ...@@ -24,12 +24,14 @@
#include "config.h" #include "config.h"
#include "PlaylistState.hxx" #include "PlaylistState.hxx"
#include "PlaylistError.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "QueueSave.hxx" #include "QueueSave.hxx"
#include "TextFile.hxx" #include "TextFile.hxx"
#include "PlayerControl.hxx" #include "PlayerControl.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigOption.hxx" #include "ConfigOption.hxx"
#include "Log.hxx"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -102,7 +104,7 @@ playlist_state_load(TextFile &file, struct playlist *playlist) ...@@ -102,7 +104,7 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
{ {
const char *line = file.ReadLine(); const char *line = file.ReadLine();
if (line == nullptr) { if (line == nullptr) {
g_warning("No playlist in state file"); LogWarning(playlist_domain, "No playlist in state file");
return; return;
} }
...@@ -111,7 +113,8 @@ playlist_state_load(TextFile &file, struct playlist *playlist) ...@@ -111,7 +113,8 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
line = file.ReadLine(); line = file.ReadLine();
if (line == nullptr) { if (line == nullptr) {
g_warning("'" PLAYLIST_STATE_FILE_PLAYLIST_END LogWarning(playlist_domain,
"'" PLAYLIST_STATE_FILE_PLAYLIST_END
"' not found in state file"); "' not found in state file");
break; break;
} }
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include "config.h" #include "config.h"
#include "QueueSave.hxx" #include "QueueSave.hxx"
#include "Playlist.hxx" #include "Queue.hxx"
#include "PlaylistError.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "SongSave.hxx" #include "SongSave.hxx"
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "TextFile.hxx" #include "TextFile.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -96,14 +98,15 @@ queue_load_song(TextFile &file, const char *line, queue *queue) ...@@ -96,14 +98,15 @@ queue_load_song(TextFile &file, const char *line, queue *queue)
Error error; Error error;
song = song_load(file, NULL, uri, error); song = song_load(file, NULL, uri, error);
if (song == NULL) { if (song == NULL) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
} else { } else {
char *endptr; char *endptr;
long ret = strtol(line, &endptr, 10); long ret = strtol(line, &endptr, 10);
if (ret < 0 || *endptr != ':' || endptr[1] == 0) { if (ret < 0 || *endptr != ':' || endptr[1] == 0) {
g_warning("Malformed playlist line in state file"); LogError(playlist_domain,
"Malformed playlist line in state file");
return; return;
} }
......
...@@ -24,15 +24,17 @@ ...@@ -24,15 +24,17 @@
#ifndef WIN32 #ifndef WIN32
#include "Log.hxx" #include "Log.hxx"
#include "LogInit.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Domain.hxx"
#include <glib.h>
#include <signal.h> #include <signal.h>
static constexpr Domain signal_handlers_domain("signal_handlers");
static EventLoop *shutdown_loop; static EventLoop *shutdown_loop;
static void static void
...@@ -51,7 +53,7 @@ x_sigaction(int signum, const struct sigaction *act) ...@@ -51,7 +53,7 @@ x_sigaction(int signum, const struct sigaction *act)
static void static void
handle_reload_event(void) handle_reload_event(void)
{ {
g_debug("got SIGHUP, reopening log files"); LogDebug(signal_handlers_domain, "got SIGHUP, reopening log files");
cycle_log_files(); cycle_log_files();
} }
......
...@@ -29,13 +29,8 @@ ...@@ -29,13 +29,8 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include <glib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "song"
#define SONG_MTIME "mtime" #define SONG_MTIME "mtime"
#define SONG_END "song_end" #define SONG_END "song_end"
......
...@@ -26,14 +26,12 @@ ...@@ -26,14 +26,12 @@
#include "Volume.hxx" #include "Volume.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Domain.hxx"
#include <glib.h> #include "Log.hxx"
#include <string.h> #include <string.h>
#include <errno.h>
#undef G_LOG_DOMAIN static constexpr Domain state_file_domain("state_file");
#define G_LOG_DOMAIN "state_file"
StateFile::StateFile(Path &&_path, StateFile::StateFile(Path &&_path,
Partition &_partition, EventLoop &_loop) Partition &_partition, EventLoop &_loop)
...@@ -66,12 +64,13 @@ StateFile::IsModified() const ...@@ -66,12 +64,13 @@ StateFile::IsModified() const
void void
StateFile::Write() StateFile::Write()
{ {
g_debug("Saving state file %s", path_utf8.c_str()); FormatDebug(state_file_domain,
"Saving state file %s", path_utf8.c_str());
FILE *fp = FOpen(path, FOpenMode::WriteText); FILE *fp = FOpen(path, FOpenMode::WriteText);
if (G_UNLIKELY(!fp)) { if (gcc_unlikely(!fp)) {
g_warning("failed to create %s: %s", FormatErrno(state_file_domain, "failed to create %s",
path_utf8.c_str(), g_strerror(errno)); path_utf8.c_str());
return; return;
} }
...@@ -89,12 +88,12 @@ StateFile::Read() ...@@ -89,12 +88,12 @@ StateFile::Read()
{ {
bool success; bool success;
g_debug("Loading state file %s", path_utf8.c_str()); FormatDebug(state_file_domain, "Loading state file %s", path_utf8.c_str());
TextFile file(path); TextFile file(path);
if (file.HasFailed()) { if (file.HasFailed()) {
g_warning("failed to open %s: %s", FormatErrno(state_file_domain, "failed to open %s",
path_utf8.c_str(), g_strerror(errno)); path_utf8.c_str());
return; return;
} }
...@@ -105,7 +104,9 @@ StateFile::Read() ...@@ -105,7 +104,9 @@ StateFile::Read()
playlist_state_restore(line, file, &partition.playlist, playlist_state_restore(line, file, &partition.playlist,
&partition.pc); &partition.pc);
if (!success) if (!success)
g_warning("Unrecognized line in state file: %s", line); FormatError(state_file_domain,
"Unrecognized line in state file: %s",
line);
} }
RememberVersions(); RememberVersions();
......
...@@ -30,6 +30,7 @@ extern "C" { ...@@ -30,6 +30,7 @@ extern "C" {
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
#include "DatabaseSimple.hxx" #include "DatabaseSimple.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
struct stats stats; struct stats stats;
...@@ -56,7 +57,7 @@ void stats_update(void) ...@@ -56,7 +57,7 @@ void stats_update(void)
stats.artist_count = stats2.artist_count; stats.artist_count = stats2.artist_count;
stats.album_count = stats2.album_count; stats.album_count = stats2.album_count;
} else { } else {
g_warning("%s", error.GetMessage()); LogError(error);
stats.song_count = 0; stats.song_count = 0;
stats.song_duration = 0; stats.song_duration = 0;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "Idle.hxx" #include "Idle.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <string> #include <string>
#include <map> #include <map>
...@@ -31,9 +32,6 @@ ...@@ -31,9 +32,6 @@
#include <sqlite3.h> #include <sqlite3.h>
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "sticker"
#if SQLITE_VERSION_NUMBER < 3003009 #if SQLITE_VERSION_NUMBER < 3003009
#define sqlite3_prepare_v2 sqlite3_prepare #define sqlite3_prepare_v2 sqlite3_prepare
#endif #endif
...@@ -85,6 +83,12 @@ static sqlite3_stmt *sticker_stmt[G_N_ELEMENTS(sticker_sql)]; ...@@ -85,6 +83,12 @@ static sqlite3_stmt *sticker_stmt[G_N_ELEMENTS(sticker_sql)];
static constexpr Domain sticker_domain("sticker"); static constexpr Domain sticker_domain("sticker");
static void
LogError(sqlite3 *db, const char *msg)
{
FormatError(sticker_domain, "%s: %s", msg, sqlite3_errmsg(db));
}
static sqlite3_stmt * static sqlite3_stmt *
sticker_prepare(const char *sql, Error &error) sticker_prepare(const char *sql, Error &error)
{ {
...@@ -186,22 +190,19 @@ sticker_load_value(const char *type, const char *uri, const char *name) ...@@ -186,22 +190,19 @@ sticker_load_value(const char *type, const char *uri, const char *name)
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return NULL; return NULL;
} }
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return NULL; return NULL;
} }
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL); ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return NULL; return NULL;
} }
...@@ -217,8 +218,7 @@ sticker_load_value(const char *type, const char *uri, const char *name) ...@@ -217,8 +218,7 @@ sticker_load_value(const char *type, const char *uri, const char *name)
value = NULL; value = NULL;
} else { } else {
/* error */ /* error */
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return NULL; return NULL;
} }
...@@ -243,15 +243,13 @@ sticker_list_values(std::map<std::string, std::string> &table, ...@@ -243,15 +243,13 @@ sticker_list_values(std::map<std::string, std::string> &table,
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -272,8 +270,7 @@ sticker_list_values(std::map<std::string, std::string> &table, ...@@ -272,8 +270,7 @@ sticker_list_values(std::map<std::string, std::string> &table,
/* no op */ /* no op */
break; break;
default: default:
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
} while (ret != SQLITE_DONE); } while (ret != SQLITE_DONE);
...@@ -303,29 +300,25 @@ sticker_update_value(const char *type, const char *uri, ...@@ -303,29 +300,25 @@ sticker_update_value(const char *type, const char *uri,
ret = sqlite3_bind_text(stmt, 1, value, -1, NULL); ret = sqlite3_bind_text(stmt, 1, value, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 2, type, -1, NULL); ret = sqlite3_bind_text(stmt, 2, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 3, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 3, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 4, name, -1, NULL); ret = sqlite3_bind_text(stmt, 4, name, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -334,8 +327,7 @@ sticker_update_value(const char *type, const char *uri, ...@@ -334,8 +327,7 @@ sticker_update_value(const char *type, const char *uri,
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) { if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -367,29 +359,25 @@ sticker_insert_value(const char *type, const char *uri, ...@@ -367,29 +359,25 @@ sticker_insert_value(const char *type, const char *uri,
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL); ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 4, value, -1, NULL); ret = sqlite3_bind_text(stmt, 4, value, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -398,8 +386,7 @@ sticker_insert_value(const char *type, const char *uri, ...@@ -398,8 +386,7 @@ sticker_insert_value(const char *type, const char *uri,
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) { if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -442,15 +429,13 @@ sticker_delete(const char *type, const char *uri) ...@@ -442,15 +429,13 @@ sticker_delete(const char *type, const char *uri)
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -459,8 +444,7 @@ sticker_delete(const char *type, const char *uri) ...@@ -459,8 +444,7 @@ sticker_delete(const char *type, const char *uri)
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) { if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -485,22 +469,19 @@ sticker_delete_value(const char *type, const char *uri, const char *name) ...@@ -485,22 +469,19 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL); ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -509,8 +490,7 @@ sticker_delete_value(const char *type, const char *uri, const char *name) ...@@ -509,8 +490,7 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) { if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -582,8 +562,7 @@ sticker_find(const char *type, const char *base_uri, const char *name, ...@@ -582,8 +562,7 @@ sticker_find(const char *type, const char *base_uri, const char *name,
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL); ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -592,15 +571,13 @@ sticker_find(const char *type, const char *base_uri, const char *name, ...@@ -592,15 +571,13 @@ sticker_find(const char *type, const char *base_uri, const char *name,
ret = sqlite3_bind_text(stmt, 2, base_uri, -1, NULL); ret = sqlite3_bind_text(stmt, 2, base_uri, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL); ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s", LogError(sticker_db, "sqlite3_bind_text() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
...@@ -618,8 +595,7 @@ sticker_find(const char *type, const char *base_uri, const char *name, ...@@ -618,8 +595,7 @@ sticker_find(const char *type, const char *base_uri, const char *name,
/* no op */ /* no op */
break; break;
default: default:
g_warning("sqlite3_step() failed: %s", LogError(sticker_db, "sqlite3_step() failed");
sqlite3_errmsg(sticker_db));
return false; return false;
} }
} while (ret != SQLITE_DONE); } while (ret != SQLITE_DONE);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "InputStream.hxx" #include "InputStream.hxx"
#include "util/fifo_buffer.h" #include "util/fifo_buffer.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -58,7 +59,7 @@ bool TextInputStream::ReadLine(std::string &line) ...@@ -58,7 +59,7 @@ bool TextInputStream::ReadLine(std::string &line)
if (nbytes > 0) if (nbytes > 0)
fifo_buffer_append(buffer, nbytes); fifo_buffer_append(buffer, nbytes);
else if (error.IsDefined()) { else if (error.IsDefined()) {
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
} else } else
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "UpdateArchive.hxx" #include "UpdateArchive.hxx"
#include "UpdateInternal.hxx" #include "UpdateInternal.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx" #include "DatabaseLock.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "Song.hxx" #include "Song.hxx"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include "ArchiveFile.hxx" #include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx" #include "ArchiveVisitor.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -53,7 +55,8 @@ update_archive_tree(Directory *directory, const char *name) ...@@ -53,7 +55,8 @@ update_archive_tree(Directory *directory, const char *name)
update_archive_tree(subdir, tmp+1); update_archive_tree(subdir, tmp+1);
} else { } else {
if (strlen(name) == 0) { if (strlen(name) == 0) {
g_warning("archive returned directory only"); LogWarning(update_domain,
"archive returned directory only");
return; return;
} }
...@@ -69,7 +72,7 @@ update_archive_tree(Directory *directory, const char *name) ...@@ -69,7 +72,7 @@ update_archive_tree(Directory *directory, const char *name)
db_unlock(); db_unlock();
modified = true; modified = true;
g_message("added %s/%s", FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
} }
} }
...@@ -105,14 +108,15 @@ update_archive_file2(Directory *parent, const char *name, ...@@ -105,14 +108,15 @@ update_archive_file2(Directory *parent, const char *name,
Error error; Error error;
ArchiveFile *file = archive_file_open(plugin, path_fs.c_str(), error); ArchiveFile *file = archive_file_open(plugin, path_fs.c_str(), error);
if (file == NULL) { if (file == NULL) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
g_debug("archive %s opened", path_fs.c_str()); FormatDebug(update_domain, "archive %s opened", path_fs.c_str());
if (directory == NULL) { if (directory == NULL) {
g_debug("creating archive directory: %s", name); FormatDebug(update_domain,
"creating archive directory: %s", name);
db_lock(); db_lock();
directory = parent->CreateChild(name); directory = parent->CreateChild(name);
/* mark this directory as archive (we use device for /* mark this directory as archive (we use device for
...@@ -131,7 +135,8 @@ update_archive_file2(Directory *parent, const char *name, ...@@ -131,7 +135,8 @@ update_archive_file2(Directory *parent, const char *name,
:directory(_directory) {} :directory(_directory) {}
virtual void VisitArchiveEntry(const char *path_utf8) override { virtual void VisitArchiveEntry(const char *path_utf8) override {
g_debug("adding archive file: %s", path_utf8); FormatDebug(update_domain,
"adding archive file: %s", path_utf8);
update_archive_tree(directory, path_utf8); update_archive_tree(directory, path_utf8);
} }
}; };
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "UpdateContainer.hxx" #include "UpdateContainer.hxx"
#include "UpdateInternal.hxx" #include "UpdateInternal.hxx"
#include "UpdateDatabase.hxx" #include "UpdateDatabase.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx" #include "DatabaseLock.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "Song.hxx" #include "Song.hxx"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "tag/TagBuilder.hxx" #include "tag/TagBuilder.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -110,7 +112,8 @@ update_container_file(Directory *directory, ...@@ -110,7 +112,8 @@ update_container_file(Directory *directory,
modified = true; modified = true;
g_message("added %s/%s", directory->GetPath(), vtrack); FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), vtrack);
g_free(vtrack); g_free(vtrack);
} }
......
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "UpdateDomain.hxx"
#include "util/Domain.hxx"
const Domain update_domain("update");
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_UPDATE_DOMAIN_HXX
#define MPD_UPDATE_DOMAIN_HXX
extern const class Domain update_domain;
#endif
...@@ -22,11 +22,13 @@ ...@@ -22,11 +22,13 @@
#include "UpdateQueue.hxx" #include "UpdateQueue.hxx"
#include "UpdateWalk.hxx" #include "UpdateWalk.hxx"
#include "UpdateRemove.hxx" #include "UpdateRemove.hxx"
#include "UpdateDomain.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "DatabaseSimple.hxx" #include "DatabaseSimple.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
extern "C" { extern "C" {
#include "stats.h" #include "stats.h"
...@@ -40,9 +42,6 @@ extern "C" { ...@@ -40,9 +42,6 @@ extern "C" {
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "update"
static enum update_progress { static enum update_progress {
UPDATE_PROGRESS_IDLE = 0, UPDATE_PROGRESS_IDLE = 0,
UPDATE_PROGRESS_RUNNING = 1, UPDATE_PROGRESS_RUNNING = 1,
...@@ -71,23 +70,22 @@ static void * update_task(void *_path) ...@@ -71,23 +70,22 @@ static void * update_task(void *_path)
const char *path = (const char *)_path; const char *path = (const char *)_path;
if (path != NULL && *path != 0) if (path != NULL && *path != 0)
g_debug("starting: %s", path); FormatDebug(update_domain, "starting: %s", path);
else else
g_debug("starting"); LogDebug(update_domain, "starting");
modified = update_walk(path, discard); modified = update_walk(path, discard);
if (modified || !db_exists()) { if (modified || !db_exists()) {
Error error; Error error;
if (!db_save(error)) if (!db_save(error))
g_warning("Failed to save database: %s", LogError(error, "Failed to save database");
error.GetMessage());
} }
if (path != NULL && *path != 0) if (path != NULL && *path != 0)
g_debug("finished: %s", path); FormatDebug(update_domain, "finished: %s", path);
else else
g_debug("finished"); LogDebug(update_domain, "finished");
g_free(_path); g_free(_path);
progress = UPDATE_PROGRESS_DONE; progress = UPDATE_PROGRESS_DONE;
...@@ -104,7 +102,7 @@ spawn_update_task(const char *path) ...@@ -104,7 +102,7 @@ spawn_update_task(const char *path)
modified = false; modified = false;
#if GLIB_CHECK_VERSION(2,32,0) #if GLIB_CHECK_VERSION(2,32,0)
update_thr = g_thread_new("updadte", update_task, g_strdup(path)); update_thr = g_thread_new("update", update_task, g_strdup(path));
#else #else
GError *e = NULL; GError *e = NULL;
update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e); update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
...@@ -114,7 +112,8 @@ spawn_update_task(const char *path) ...@@ -114,7 +112,8 @@ spawn_update_task(const char *path)
if (++update_task_id > update_task_id_max) if (++update_task_id > update_task_id_max)
update_task_id = 1; update_task_id = 1;
g_debug("spawned thread for update job id %i", update_task_id); FormatDebug(update_domain,
"spawned thread for update job id %i", update_task_id);
} }
unsigned unsigned
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "UpdateIO.hxx" #include "UpdateIO.hxx"
#include "src/UpdateDomain.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "Log.hxx"
#include <glib.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
...@@ -39,8 +39,8 @@ stat_directory(const Directory *directory, struct stat *st) ...@@ -39,8 +39,8 @@ stat_directory(const Directory *directory, struct stat *st)
if (!StatFile(path_fs, *st)) { if (!StatFile(path_fs, *st)) {
int error = errno; int error = errno;
const std::string path_utf8 = path_fs.ToUTF8(); const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s", FormatErrno(update_domain, error,
path_utf8.c_str(), g_strerror(error)); "Failed to stat %s", path_utf8.c_str());
return -1; return -1;
} }
...@@ -58,8 +58,8 @@ stat_directory_child(const Directory *parent, const char *name, ...@@ -58,8 +58,8 @@ stat_directory_child(const Directory *parent, const char *name,
if (!StatFile(path_fs, *st)) { if (!StatFile(path_fs, *st)) {
int error = errno; int error = errno;
const std::string path_utf8 = path_fs.ToUTF8(); const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s", FormatErrno(update_domain, error,
path_utf8.c_str(), g_strerror(error)); "Failed to stat %s", path_utf8.c_str());
return -1; return -1;
} }
......
...@@ -19,14 +19,15 @@ ...@@ -19,14 +19,15 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "UpdateRemove.hxx" #include "UpdateRemove.hxx"
#include "UpdateDomain.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "Instance.hxx" #include "Instance.hxx"
#include "Log.hxx"
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
#include "StickerDatabase.hxx" #include "StickerDatabase.hxx"
...@@ -54,7 +55,7 @@ song_remove_event(void) ...@@ -54,7 +55,7 @@ song_remove_event(void)
assert(removed_song != NULL); assert(removed_song != NULL);
uri = removed_song->GetURI(); uri = removed_song->GetURI();
g_message("removing %s", uri); FormatInfo(update_domain, "removing %s", uri);
g_free(uri); g_free(uri);
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
......
...@@ -23,13 +23,13 @@ ...@@ -23,13 +23,13 @@
#include "UpdateIO.hxx" #include "UpdateIO.hxx"
#include "UpdateDatabase.hxx" #include "UpdateDatabase.hxx"
#include "UpdateContainer.hxx" #include "UpdateContainer.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx" #include "DatabaseLock.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "DecoderPlugin.hxx" #include "DecoderPlugin.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "Log.hxx"
#include <glib.h>
#include <unistd.h> #include <unistd.h>
...@@ -43,7 +43,8 @@ update_song_file2(Directory *directory, ...@@ -43,7 +43,8 @@ update_song_file2(Directory *directory,
db_unlock(); db_unlock();
if (!directory_child_access(directory, name, R_OK)) { if (!directory_child_access(directory, name, R_OK)) {
g_warning("no read permissions on %s/%s", FormatError(update_domain,
"no read permissions on %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
if (song != NULL) { if (song != NULL) {
db_lock(); db_lock();
...@@ -67,10 +68,12 @@ update_song_file2(Directory *directory, ...@@ -67,10 +68,12 @@ update_song_file2(Directory *directory,
} }
if (song == NULL) { if (song == NULL) {
g_debug("reading %s/%s", directory->GetPath(), name); FormatDebug(update_domain, "reading %s/%s",
directory->GetPath(), name);
song = Song::LoadFile(name, directory); song = Song::LoadFile(name, directory);
if (song == NULL) { if (song == NULL) {
g_debug("ignoring unrecognized file %s/%s", FormatDebug(update_domain,
"ignoring unrecognized file %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
return; return;
} }
...@@ -80,13 +83,14 @@ update_song_file2(Directory *directory, ...@@ -80,13 +83,14 @@ update_song_file2(Directory *directory,
db_unlock(); db_unlock();
modified = true; modified = true;
g_message("added %s/%s", FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
} else if (st->st_mtime != song->mtime || walk_discard) { } else if (st->st_mtime != song->mtime || walk_discard) {
g_message("updating %s/%s", FormatInfo(update_domain, "updating %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
if (!song->UpdateFile()) { if (!song->UpdateFile()) {
g_debug("deleting unrecognized file %s/%s", FormatDebug(update_domain,
"deleting unrecognized file %s/%s",
directory->GetPath(), name); directory->GetPath(), name);
db_lock(); db_lock();
delete_song(directory, song); delete_song(directory, song);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "UpdateDatabase.hxx" #include "UpdateDatabase.hxx"
#include "UpdateSong.hxx" #include "UpdateSong.hxx"
#include "UpdateArchive.hxx" #include "UpdateArchive.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx" #include "DatabaseLock.hxx"
#include "DatabaseSimple.hxx" #include "DatabaseSimple.hxx"
#include "Directory.hxx" #include "Directory.hxx"
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx" #include "fs/DirectoryReader.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -49,9 +51,6 @@ ...@@ -49,9 +51,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "update"
bool walk_discard; bool walk_discard;
bool modified; bool modified;
...@@ -185,7 +184,7 @@ find_inode_ancestor(Directory *parent, ino_t inode, dev_t device) ...@@ -185,7 +184,7 @@ find_inode_ancestor(Directory *parent, ino_t inode, dev_t device)
return -1; return -1;
if (parent->inode == inode && parent->device == device) { if (parent->inode == inode && parent->device == device) {
g_debug("recursive directory found"); LogDebug(update_domain, "recursive directory found");
return 1; return 1;
} }
...@@ -257,7 +256,8 @@ update_directory_child(Directory *directory, ...@@ -257,7 +256,8 @@ update_directory_child(Directory *directory,
db_unlock(); db_unlock();
} }
} else { } else {
g_debug("update: %s is not a directory, archive or music", name); FormatDebug(update_domain,
"%s is not a directory, archive or music", name);
} }
} }
...@@ -352,8 +352,9 @@ update_directory(Directory *directory, const struct stat *st) ...@@ -352,8 +352,9 @@ update_directory(Directory *directory, const struct stat *st)
if (reader.HasFailed()) { if (reader.HasFailed()) {
int error = errno; int error = errno;
const auto path_utf8 = path_fs.ToUTF8(); const auto path_utf8 = path_fs.ToUTF8();
g_warning("Failed to open directory %s: %s", FormatErrno(update_domain, error,
path_utf8.c_str(), g_strerror(error)); "Failed to open directory %s",
path_utf8.c_str());
return false; return false;
} }
......
...@@ -22,17 +22,18 @@ ...@@ -22,17 +22,18 @@
#include "MixerAll.hxx" #include "MixerAll.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "volume"
#define SW_VOLUME_STATE "sw_volume: " #define SW_VOLUME_STATE "sw_volume: "
static constexpr Domain volume_domain("volume");
static unsigned volume_software_set = 100; static unsigned volume_software_set = 100;
/** the cached hardware mixer value; invalid if negative */ /** the cached hardware mixer value; invalid if negative */
...@@ -122,7 +123,8 @@ read_sw_volume_state(const char *line) ...@@ -122,7 +123,8 @@ read_sw_volume_state(const char *line)
if (*end == 0 && sv >= 0 && sv <= 100) if (*end == 0 && sv >= 0 && sv <= 100)
software_volume_change(sv); software_volume_change(sv);
else else
g_warning("Can't parse software volume: %s\n", line); FormatWarning(volume_domain,
"Can't parse software volume: %s", line);
return true; return true;
} }
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "Listen.hxx" #include "Listen.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -36,8 +38,7 @@ ...@@ -36,8 +38,7 @@
#include <avahi-glib/glib-watch.h> #include <avahi-glib/glib-watch.h>
#undef G_LOG_DOMAIN static constexpr Domain avahi_domain("avahi");
#define G_LOG_DOMAIN "avahi"
static char *avahiName; static char *avahiName;
static int avahiRunning; static int avahiRunning;
...@@ -58,12 +59,14 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -58,12 +59,14 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
char *n; char *n;
assert(g); assert(g);
g_debug("Service group changed to state %d", state); FormatDebug(avahi_domain,
"Service group changed to state %d", state);
switch (state) { switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED: case AVAHI_ENTRY_GROUP_ESTABLISHED:
/* The entry group has been established successfully */ /* The entry group has been established successfully */
g_message("Service '%s' successfully established.", FormatInfo(avahi_domain,
"Service '%s' successfully established.",
avahiName); avahiName);
break; break;
...@@ -73,7 +76,8 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -73,7 +76,8 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
avahi_free(avahiName); avahi_free(avahiName);
avahiName = n; avahiName = n;
g_message("Service name collision, renaming service to '%s'", FormatInfo(avahi_domain,
"Service name collision, renaming service to '%s'",
avahiName); avahiName);
/* And recreate the services */ /* And recreate the services */
...@@ -81,7 +85,8 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -81,7 +85,8 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
break; break;
case AVAHI_ENTRY_GROUP_FAILURE: case AVAHI_ENTRY_GROUP_FAILURE:
g_warning("Entry group failure: %s", FormatError(avahi_domain,
"Entry group failure: %s",
avahi_strerror(avahi_client_errno avahi_strerror(avahi_client_errno
(avahi_entry_group_get_client(g)))); (avahi_entry_group_get_client(g))));
/* Some kind of failure happened while we were registering our services */ /* Some kind of failure happened while we were registering our services */
...@@ -89,26 +94,29 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -89,26 +94,29 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
break; break;
case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_UNCOMMITED:
g_debug("Service group is UNCOMMITED"); LogDebug(avahi_domain, "Service group is UNCOMMITED");
break; break;
case AVAHI_ENTRY_GROUP_REGISTERING: case AVAHI_ENTRY_GROUP_REGISTERING:
g_debug("Service group is REGISTERING"); LogDebug(avahi_domain, "Service group is REGISTERING");
} }
} }
/* Registers a new service with avahi */ /* Registers a new service with avahi */
static void avahiRegisterService(AvahiClient * c) static void avahiRegisterService(AvahiClient * c)
{ {
FormatDebug(avahi_domain, "Registering service %s/%s",
SERVICE_TYPE, avahiName);
int ret; int ret;
assert(c); assert(c);
g_debug("Registering service %s/%s", SERVICE_TYPE, avahiName);
/* If this is the first time we're called, /* If this is the first time we're called,
* let's create a new entry group */ * let's create a new entry group */
if (!avahiGroup) { if (!avahiGroup) {
avahiGroup = avahi_entry_group_new(c, avahiGroupCallback, NULL); avahiGroup = avahi_entry_group_new(c, avahiGroupCallback, NULL);
if (!avahiGroup) { if (!avahiGroup) {
g_warning("Failed to create avahi EntryGroup: %s", FormatError(avahi_domain,
"Failed to create avahi EntryGroup: %s",
avahi_strerror(avahi_client_errno(c))); avahi_strerror(avahi_client_errno(c)));
goto fail; goto fail;
} }
...@@ -124,15 +132,15 @@ static void avahiRegisterService(AvahiClient * c) ...@@ -124,15 +132,15 @@ static void avahiRegisterService(AvahiClient * c)
avahiName, SERVICE_TYPE, NULL, avahiName, SERVICE_TYPE, NULL,
NULL, listen_port, NULL); NULL, listen_port, NULL);
if (ret < 0) { if (ret < 0) {
g_warning("Failed to add service %s: %s", SERVICE_TYPE, FormatError(avahi_domain, "Failed to add service %s: %s",
avahi_strerror(ret)); SERVICE_TYPE, avahi_strerror(ret));
goto fail; goto fail;
} }
/* Tell the server to register the service group */ /* Tell the server to register the service group */
ret = avahi_entry_group_commit(avahiGroup); ret = avahi_entry_group_commit(avahiGroup);
if (ret < 0) { if (ret < 0) {
g_warning("Failed to commit service group: %s", FormatError(avahi_domain, "Failed to commit service group: %s",
avahi_strerror(ret)); avahi_strerror(ret));
goto fail; goto fail;
} }
...@@ -150,11 +158,11 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state, ...@@ -150,11 +158,11 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
assert(c); assert(c);
/* Called whenever the client or server state changes */ /* Called whenever the client or server state changes */
g_debug("Client changed to state %d", state); FormatDebug(avahi_domain, "Client changed to state %d", state);
switch (state) { switch (state) {
case AVAHI_CLIENT_S_RUNNING: case AVAHI_CLIENT_S_RUNNING:
g_debug("Client is RUNNING"); LogDebug(avahi_domain, "Client is RUNNING");
/* The server has startup successfully and registered its host /* The server has startup successfully and registered its host
* name on the network, so it's time to create our services */ * name on the network, so it's time to create our services */
...@@ -165,7 +173,8 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state, ...@@ -165,7 +173,8 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
case AVAHI_CLIENT_FAILURE: case AVAHI_CLIENT_FAILURE:
reason = avahi_client_errno(c); reason = avahi_client_errno(c);
if (reason == AVAHI_ERR_DISCONNECTED) { if (reason == AVAHI_ERR_DISCONNECTED) {
g_message("Client Disconnected, will reconnect shortly"); LogInfo(avahi_domain,
"Client Disconnected, will reconnect shortly");
if (avahiGroup) { if (avahiGroup) {
avahi_entry_group_free(avahiGroup); avahi_entry_group_free(avahiGroup);
avahiGroup = NULL; avahiGroup = NULL;
...@@ -178,51 +187,57 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state, ...@@ -178,51 +187,57 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
avahiClientCallback, NULL, avahiClientCallback, NULL,
&reason); &reason);
if (!avahiClient) { if (!avahiClient) {
g_warning("Could not reconnect: %s", FormatWarning(avahi_domain,
"Could not reconnect: %s",
avahi_strerror(reason)); avahi_strerror(reason));
avahiRunning = 0; avahiRunning = 0;
} }
} else { } else {
g_warning("Client failure: %s (terminal)", FormatWarning(avahi_domain,
"Client failure: %s (terminal)",
avahi_strerror(reason)); avahi_strerror(reason));
avahiRunning = 0; avahiRunning = 0;
} }
break; break;
case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_COLLISION:
g_debug("Client is COLLISION"); LogDebug(avahi_domain, "Client is COLLISION");
/* Let's drop our registered services. When the server is back /* Let's drop our registered services. When the server is back
* in AVAHI_SERVER_RUNNING state we will register them * in AVAHI_SERVER_RUNNING state we will register them
* again with the new host name. */ * again with the new host name. */
if (avahiGroup) { if (avahiGroup) {
g_debug("Resetting group"); LogDebug(avahi_domain, "Resetting group");
avahi_entry_group_reset(avahiGroup); avahi_entry_group_reset(avahiGroup);
} }
break;
case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_REGISTERING:
g_debug("Client is REGISTERING"); LogDebug(avahi_domain, "Client is REGISTERING");
/* The server records are now being established. This /* The server records are now being established. This
* might be caused by a host name change. We need to wait * might be caused by a host name change. We need to wait
* for our own records to register until the host name is * for our own records to register until the host name is
* properly esatblished. */ * properly esatblished. */
if (avahiGroup) { if (avahiGroup) {
g_debug("Resetting group"); LogDebug(avahi_domain, "Resetting group");
avahi_entry_group_reset(avahiGroup); avahi_entry_group_reset(avahiGroup);
} }
break; break;
case AVAHI_CLIENT_CONNECTING: case AVAHI_CLIENT_CONNECTING:
g_debug("Client is CONNECTING"); LogDebug(avahi_domain, "Client is CONNECTING");
break;
} }
} }
void void
AvahiInit(EventLoop &loop, const char *serviceName) AvahiInit(EventLoop &loop, const char *serviceName)
{ {
int error; LogDebug(avahi_domain, "Initializing interface");
g_debug("Initializing interface");
if (!avahi_is_valid_service_name(serviceName)) if (!avahi_is_valid_service_name(serviceName))
FormatFatalError("Invalid zeroconf_name \"%s\"", serviceName); FormatFatalError("Invalid zeroconf_name \"%s\"", serviceName);
...@@ -241,11 +256,12 @@ AvahiInit(EventLoop &loop, const char *serviceName) ...@@ -241,11 +256,12 @@ AvahiInit(EventLoop &loop, const char *serviceName)
avahi_poll = avahi_glib_poll_get(avahi_glib_poll); avahi_poll = avahi_glib_poll_get(avahi_glib_poll);
#endif #endif
int error;
avahiClient = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, avahiClient = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL,
avahiClientCallback, NULL, &error); avahiClientCallback, NULL, &error);
if (!avahiClient) { if (!avahiClient) {
g_warning("Failed to create client: %s", FormatError(avahi_domain, "Failed to create client: %s",
avahi_strerror(error)); avahi_strerror(error));
AvahiDeinit(); AvahiDeinit();
} }
...@@ -254,7 +270,7 @@ AvahiInit(EventLoop &loop, const char *serviceName) ...@@ -254,7 +270,7 @@ AvahiInit(EventLoop &loop, const char *serviceName)
void void
AvahiDeinit(void) AvahiDeinit(void)
{ {
g_debug("Shutting down interface"); LogDebug(avahi_domain, "Shutting down interface");
if (avahiGroup) { if (avahiGroup) {
avahi_entry_group_free(avahiGroup); avahi_entry_group_free(avahiGroup);
......
...@@ -22,14 +22,15 @@ ...@@ -22,14 +22,15 @@
#include "ZeroconfInternal.hxx" #include "ZeroconfInternal.hxx"
#include "Listen.hxx" #include "Listen.hxx"
#include "event/SocketMonitor.hxx" #include "event/SocketMonitor.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "gcc.h" #include "gcc.h"
#include <glib.h> #include <glib.h>
#include <dns_sd.h> #include <dns_sd.h>
#undef G_LOG_DOMAIN static constexpr Domain bonjour_domain("bonjour");
#define G_LOG_DOMAIN "bonjour"
class BonjourMonitor final : public SocketMonitor { class BonjourMonitor final : public SocketMonitor {
DNSServiceRef service_ref; DNSServiceRef service_ref;
...@@ -64,11 +65,14 @@ dnsRegisterCallback(gcc_unused DNSServiceRef sdRef, ...@@ -64,11 +65,14 @@ dnsRegisterCallback(gcc_unused DNSServiceRef sdRef,
gcc_unused void *context) gcc_unused void *context)
{ {
if (errorCode != kDNSServiceErr_NoError) { if (errorCode != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service."); LogError(bonjour_domain,
"Failed to register zeroconf service");
bonjour_monitor->Cancel(); bonjour_monitor->Cancel();
} else { } else {
g_debug("Registered zeroconf service with name '%s'", name); FormatDebug(bonjour_domain,
"Registered zeroconf service with name '%s'",
name);
} }
} }
...@@ -85,7 +89,8 @@ BonjourInit(EventLoop &loop, const char *service_name) ...@@ -85,7 +89,8 @@ BonjourInit(EventLoop &loop, const char *service_name)
NULL); NULL);
if (error != kDNSServiceErr_NoError) { if (error != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service."); LogError(bonjour_domain,
"Failed to register zeroconf service");
if (dnsReference) { if (dnsReference) {
DNSServiceRefDeallocate(dnsReference); DNSServiceRefDeallocate(dnsReference);
......
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "ConfigOption.hxx" #include "ConfigOption.hxx"
#include "Listen.hxx" #include "Listen.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "gcc.h" #include "gcc.h"
#include <glib.h> static constexpr Domain zeroconf_domain("zeroconf");
/* The default service name to publish /* The default service name to publish
* (overridden by 'zeroconf_name' config parameter) * (overridden by 'zeroconf_name' config parameter)
...@@ -48,7 +50,8 @@ ZeroconfInit(gcc_unused EventLoop &loop) ...@@ -48,7 +50,8 @@ ZeroconfInit(gcc_unused EventLoop &loop)
return; return;
if (listen_port <= 0) { if (listen_port <= 0) {
g_warning("No global port, disabling zeroconf"); LogInfo(zeroconf_domain,
"No global port, disabling zeroconf");
zeroconfEnabled = false; zeroconfEnabled = false;
return; return;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -169,7 +170,7 @@ SimpleDatabase::Open(Error &error) ...@@ -169,7 +170,7 @@ SimpleDatabase::Open(Error &error)
if (!Load(error)) { if (!Load(error)) {
root->Free(); root->Free();
g_warning("Failed to load database: %s", error.GetMessage()); LogError(error);
error.Clear(); error.Clear();
if (!Check(error)) if (!Check(error))
...@@ -284,15 +285,15 @@ SimpleDatabase::Save(Error &error) ...@@ -284,15 +285,15 @@ SimpleDatabase::Save(Error &error)
{ {
db_lock(); db_lock();
g_debug("removing empty directories from DB"); LogDebug(simple_db_domain, "removing empty directories from DB");
root->PruneEmpty(); root->PruneEmpty();
g_debug("sorting DB"); LogDebug(simple_db_domain, "sorting DB");
root->Sort(); root->Sort();
db_unlock(); db_unlock();
g_debug("writing DB"); LogDebug(simple_db_domain, "writing DB");
FILE *fp = FOpen(path, FOpenMode::WriteText); FILE *fp = FOpen(path, FOpenMode::WriteText);
if (!fp) { if (!fp) {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <adplug/adplug.h> #include <adplug/adplug.h>
#include <adplug/emuopl.h> #include <adplug/emuopl.h>
...@@ -31,9 +32,6 @@ ...@@ -31,9 +32,6 @@
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "adplug"
static unsigned sample_rate; static unsigned sample_rate;
static bool static bool
...@@ -43,7 +41,7 @@ adplug_init(const config_param &param) ...@@ -43,7 +41,7 @@ adplug_init(const config_param &param)
sample_rate = param.GetBlockValue("sample_rate", 48000u); sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, error)) { if (!audio_check_sample_rate(sample_rate, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
......
...@@ -24,19 +24,19 @@ ...@@ -24,19 +24,19 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <audiofile.h> #include <audiofile.h>
#include <af_vfs.h> #include <af_vfs.h>
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#undef G_LOG_DOMAIN #include <assert.h>
#define G_LOG_DOMAIN "audiofile"
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */ /* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020 #define CHUNK_SIZE 1020
static constexpr Domain audiofile_domain("audiofile");
static int audiofile_get_duration(const char *file) static int audiofile_get_duration(const char *file)
{ {
int total_time; int total_time;
...@@ -59,7 +59,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length) ...@@ -59,7 +59,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
Error error; Error error;
size_t nbytes = is->LockRead(data, length, error); size_t nbytes = is->LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) { if (nbytes == 0 && error.IsDefined()) {
g_warning("%s", error.GetMessage()); LogError(error);
return -1; return -1;
} }
...@@ -143,7 +143,8 @@ audiofile_setup_sample_format(AFfilehandle af_fp) ...@@ -143,7 +143,8 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
if (!audio_valid_sample_format(audiofile_bits_to_sample_format(bits))) { if (!audio_valid_sample_format(audiofile_bits_to_sample_format(bits))) {
g_debug("input file has %d bit samples, converting to 16", FormatDebug(audiofile_domain,
"input file has %d bit samples, converting to 16",
bits); bits);
bits = 16; bits = 16;
} }
...@@ -168,7 +169,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -168,7 +169,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
char chunk[CHUNK_SIZE]; char chunk[CHUNK_SIZE];
if (!is->IsSeekable()) { if (!is->IsSeekable()) {
g_warning("not seekable"); LogWarning(audiofile_domain, "not seekable");
return; return;
} }
...@@ -176,7 +177,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -176,7 +177,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
af_fp = afOpenVirtualFile(vf, "r", nullptr); af_fp = afOpenVirtualFile(vf, "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) { if (af_fp == AF_NULL_FILEHANDLE) {
g_warning("failed to input stream\n"); LogWarning(audiofile_domain, "failed to input stream");
return; return;
} }
...@@ -186,7 +187,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -186,7 +187,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
audiofile_setup_sample_format(af_fp), audiofile_setup_sample_format(af_fp),
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK), afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
error)) { error)) {
g_warning("%s", error.GetMessage()); LogError(error);
afCloseFile(af_fp); afCloseFile(af_fp);
return; return;
} }
...@@ -232,7 +233,8 @@ audiofile_scan_file(const char *file, ...@@ -232,7 +233,8 @@ audiofile_scan_file(const char *file,
int total_time = audiofile_get_duration(file); int total_time = audiofile_get_duration(file);
if (total_time < 0) { if (total_time < 0) {
g_debug("Failed to get total song time from: %s\n", FormatWarning(audiofile_domain,
"Failed to get total song time from: %s",
file); file);
return false; return false;
} }
......
...@@ -35,13 +35,11 @@ ...@@ -35,13 +35,11 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "DsdLib.hxx" #include "DsdLib.hxx"
#include "Log.hxx"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */ #include <stdio.h> /* for SEEK_SET, SEEK_CUR */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "dsdiff"
struct DsdiffHeader { struct DsdiffHeader {
struct dsdlib_id id; struct dsdlib_id id;
uint32_t size_high, size_low; uint32_t size_high, size_low;
...@@ -437,7 +435,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -437,7 +435,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8, if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD, SampleFormat::DSD,
metadata.channels, error)) { metadata.channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
......
...@@ -36,13 +36,11 @@ ...@@ -36,13 +36,11 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "DsdLib.hxx" #include "DsdLib.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "Log.hxx"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */ #include <stdio.h> /* for SEEK_SET, SEEK_CUR */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "dsf"
struct DsfMetaData { struct DsfMetaData {
unsigned sample_rate, channels; unsigned sample_rate, channels;
bool bitreverse; bool bitreverse;
...@@ -290,7 +288,7 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -290,7 +288,7 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8, if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD, SampleFormat::DSD,
metadata.channels, error)) { metadata.channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
/* Calculate song time from DSD chunk size and sample frequency */ /* Calculate song time from DSD chunk size and sample frequency */
......
...@@ -26,18 +26,14 @@ ...@@ -26,18 +26,14 @@
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <neaacdec.h> #include <neaacdec.h>
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "faad"
#define AAC_MAX_CHANNELS 6 #define AAC_MAX_CHANNELS 6
static const unsigned adts_sample_rates[] = static const unsigned adts_sample_rates[] =
...@@ -395,7 +391,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -395,7 +391,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
Error error; Error error;
ret = faad_decoder_init(decoder, buffer, audio_format, error); ret = faad_decoder_init(decoder, buffer, audio_format, error);
if (!ret) { if (!ret) {
g_warning("%s", error.GetMessage()); LogError(error);
NeAACDecClose(decoder); NeAACDecClose(decoder);
return; return;
} }
...@@ -424,19 +420,22 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -424,19 +420,22 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
decoded = faad_decoder_decode(decoder, buffer, &frame_info); decoded = faad_decoder_decode(decoder, buffer, &frame_info);
if (frame_info.error > 0) { if (frame_info.error > 0) {
g_warning("error decoding AAC stream: %s\n", FormatWarning(faad_decoder_domain,
"error decoding AAC stream: %s",
NeAACDecGetErrorMessage(frame_info.error)); NeAACDecGetErrorMessage(frame_info.error));
break; break;
} }
if (frame_info.channels != audio_format.channels) { if (frame_info.channels != audio_format.channels) {
g_warning("channel count changed from %u to %u", FormatInfo(faad_decoder_domain,
"channel count changed from %u to %u",
audio_format.channels, frame_info.channels); audio_format.channels, frame_info.channels);
break; break;
} }
if (frame_info.samplerate != audio_format.sample_rate) { if (frame_info.samplerate != audio_format.sample_rate) {
g_warning("sample rate changed from %u to %lu", FormatInfo(faad_decoder_domain,
"sample rate changed from %u to %lu",
audio_format.sample_rate, audio_format.sample_rate,
(unsigned long)frame_info.samplerate); (unsigned long)frame_info.samplerate);
break; break;
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "InputStream.hxx" #include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "LogV.hxx"
#include <glib.h> #include <glib.h>
...@@ -50,27 +52,26 @@ extern "C" { ...@@ -50,27 +52,26 @@ extern "C" {
#include <libavutil/dict.h> #include <libavutil/dict.h>
} }
#undef G_LOG_DOMAIN static constexpr Domain ffmpeg_domain("ffmpeg");
#define G_LOG_DOMAIN "ffmpeg"
/* suppress the ffmpeg compatibility macro */ /* suppress the ffmpeg compatibility macro */
#ifdef SampleFormat #ifdef SampleFormat
#undef SampleFormat #undef SampleFormat
#endif #endif
static GLogLevelFlags static LogLevel
level_ffmpeg_to_glib(int level) import_ffmpeg_level(int level)
{ {
if (level <= AV_LOG_FATAL) if (level <= AV_LOG_FATAL)
return G_LOG_LEVEL_CRITICAL; return LogLevel::ERROR;
if (level <= AV_LOG_ERROR) if (level <= AV_LOG_WARNING)
return G_LOG_LEVEL_WARNING; return LogLevel::WARNING;
if (level <= AV_LOG_INFO) if (level <= AV_LOG_INFO)
return G_LOG_LEVEL_MESSAGE; return LogLevel::INFO;
return G_LOG_LEVEL_DEBUG; return LogLevel::DEBUG;
} }
static void static void
...@@ -83,8 +84,9 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level, ...@@ -83,8 +84,9 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level,
cls = *(const AVClass *const*)ptr; cls = *(const AVClass *const*)ptr;
if (cls != NULL) { if (cls != NULL) {
char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); char *domain = g_strconcat(ffmpeg_domain.GetName(), "/", cls->item_name(ptr), NULL);
g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl); const Domain d(domain);
LogFormatV(d, import_ffmpeg_level(level), fmt, vl);
g_free(domain); g_free(domain);
} }
} }
...@@ -287,7 +289,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, ...@@ -287,7 +289,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
if (len < 0) { if (len < 0) {
/* if error, we skip the frame */ /* if error, we skip the frame */
g_message("decoding failed, frame skipped\n"); LogInfo(ffmpeg_domain,
"decoding failed, frame skipped");
break; break;
} }
...@@ -328,10 +331,12 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) ...@@ -328,10 +331,12 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer), const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
sample_fmt); sample_fmt);
if (name != NULL) if (name != NULL)
g_warning("Unsupported libavcodec SampleFormat value: %s (%d)", FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt); name, sample_fmt);
else else
g_warning("Unsupported libavcodec SampleFormat value: %d", FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %d",
sample_fmt); sample_fmt);
return SampleFormat::UNDEFINED; return SampleFormat::UNDEFINED;
} }
...@@ -377,12 +382,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -377,12 +382,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (input_format == NULL) if (input_format == NULL)
return; return;
g_debug("detected input format '%s' (%s)", FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
input_format->name, input_format->long_name); input_format->name, input_format->long_name);
AvioStream stream(decoder, input); AvioStream stream(decoder, input);
if (!stream.Open()) { if (!stream.Open()) {
g_warning("Failed to open stream"); LogError(ffmpeg_domain, "Failed to open stream");
return; return;
} }
...@@ -391,21 +396,21 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -391,21 +396,21 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (mpd_ffmpeg_open_input(&format_context, stream.io, if (mpd_ffmpeg_open_input(&format_context, stream.io,
input->uri.c_str(), input->uri.c_str(),
input_format) != 0) { input_format) != 0) {
g_warning("Open failed\n"); LogError(ffmpeg_domain, "Open failed");
return; return;
} }
const int find_result = const int find_result =
avformat_find_stream_info(format_context, NULL); avformat_find_stream_info(format_context, NULL);
if (find_result < 0) { if (find_result < 0) {
g_warning("Couldn't find stream info\n"); LogError(ffmpeg_domain, "Couldn't find stream info");
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
int audio_stream = ffmpeg_find_audio_stream(format_context); int audio_stream = ffmpeg_find_audio_stream(format_context);
if (audio_stream == -1) { if (audio_stream == -1) {
g_warning("No audio stream inside\n"); LogError(ffmpeg_domain, "No audio stream inside");
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
...@@ -414,12 +419,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -414,12 +419,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVCodecContext *codec_context = av_stream->codec; AVCodecContext *codec_context = av_stream->codec;
if (codec_context->codec_name[0] != 0) if (codec_context->codec_name[0] != 0)
g_debug("codec '%s'", codec_context->codec_name); FormatDebug(ffmpeg_domain, "codec '%s'",
codec_context->codec_name);
AVCodec *codec = avcodec_find_decoder(codec_context->codec_id); AVCodec *codec = avcodec_find_decoder(codec_context->codec_id);
if (!codec) { if (!codec) {
g_warning("Unsupported audio codec\n"); LogError(ffmpeg_domain, "Unsupported audio codec");
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
...@@ -435,7 +441,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -435,7 +441,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
codec_context->sample_rate, codec_context->sample_rate,
sample_format, sample_format,
codec_context->channels, error)) { codec_context->channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
...@@ -447,7 +453,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -447,7 +453,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
const int open_result = avcodec_open2(codec_context, codec, NULL); const int open_result = avcodec_open2(codec_context, codec, NULL);
if (open_result < 0) { if (open_result < 0) {
g_warning("Could not open codec\n"); LogError(ffmpeg_domain, "Could not open codec");
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
...@@ -461,7 +467,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ...@@ -461,7 +467,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVFrame *frame = avcodec_alloc_frame(); AVFrame *frame = avcodec_alloc_frame();
if (!frame) { if (!frame) {
g_warning("Could not allocate frame\n"); LogError(ffmpeg_domain, "Could not allocate frame");
avformat_close_input(&format_context); avformat_close_input(&format_context);
return; return;
} }
......
...@@ -25,9 +25,6 @@ ...@@ -25,9 +25,6 @@
#include "tag/TagTable.hxx" #include "tag/TagTable.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
static const struct tag_table ffmpeg_tags[] = { static const struct tag_table ffmpeg_tags[] = {
{ "year", TAG_DATE }, { "year", TAG_DATE },
{ "author-sort", TAG_ARTIST_SORT }, { "author-sort", TAG_ARTIST_SORT },
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#include "FlacPcm.hxx" #include "FlacPcm.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include <glib.h> #include "Log.hxx"
#include <assert.h> #include <assert.h>
...@@ -74,7 +74,7 @@ flac_got_stream_info(struct flac_data *data, ...@@ -74,7 +74,7 @@ flac_got_stream_info(struct flac_data *data,
stream_info->sample_rate, stream_info->sample_rate,
flac_sample_format(stream_info->bits_per_sample), flac_sample_format(stream_info->bits_per_sample),
stream_info->channels, error)) { stream_info->channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
data->unsupported = true; data->unsupported = true;
return; return;
} }
...@@ -136,7 +136,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header) ...@@ -136,7 +136,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
header->sample_rate, header->sample_rate,
flac_sample_format(header->bits_per_sample), flac_sample_format(header->bits_per_sample),
header->channels, error)) { header->channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
data->unsupported = true; data->unsupported = true;
return false; return false;
} }
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#include <FLAC/stream_decoder.h> #include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h> #include <FLAC/metadata.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "flac"
struct flac_data : public FlacInput { struct flac_data : public FlacInput {
PcmBuffer buffer; PcmBuffer buffer;
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "FlacDecoderPlugin.h" #include "FlacDecoderPlugin.h"
#include "FlacDomain.hxx"
#include "FlacCommon.hxx" #include "FlacCommon.hxx"
#include "FlacMetadata.hxx" #include "FlacMetadata.hxx"
#include "OggCodec.hxx" #include "OggCodec.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -54,7 +56,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state) ...@@ -54,7 +56,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
break; break;
} }
g_warning("%s\n", FLAC__StreamDecoderStateString[state]); LogError(flac_domain, FLAC__StreamDecoderStateString[state]);
} }
static void flacMetadata(gcc_unused const FLAC__StreamDecoder * dec, static void flacMetadata(gcc_unused const FLAC__StreamDecoder * dec,
...@@ -90,7 +92,8 @@ flac_scan_file(const char *file, ...@@ -90,7 +92,8 @@ flac_scan_file(const char *file,
{ {
FlacMetadataChain chain; FlacMetadataChain chain;
if (!chain.Read(file)) { if (!chain.Read(file)) {
g_debug("Failed to read FLAC tags: %s", FormatDebug(flac_domain,
"Failed to read FLAC tags: %s",
chain.GetStatusString()); chain.GetStatusString());
return false; return false;
} }
...@@ -105,7 +108,8 @@ flac_scan_stream(struct input_stream *is, ...@@ -105,7 +108,8 @@ flac_scan_stream(struct input_stream *is,
{ {
FlacMetadataChain chain; FlacMetadataChain chain;
if (!chain.Read(is)) { if (!chain.Read(is)) {
g_debug("Failed to read FLAC tags: %s", FormatDebug(flac_domain,
"Failed to read FLAC tags: %s",
chain.GetStatusString()); chain.GetStatusString());
return false; return false;
} }
...@@ -122,12 +126,14 @@ flac_decoder_new(void) ...@@ -122,12 +126,14 @@ flac_decoder_new(void)
{ {
FLAC__StreamDecoder *sd = FLAC__stream_decoder_new(); FLAC__StreamDecoder *sd = FLAC__stream_decoder_new();
if (sd == nullptr) { if (sd == nullptr) {
g_warning("FLAC__stream_decoder_new() failed"); LogError(flac_domain,
"FLAC__stream_decoder_new() failed");
return nullptr; return nullptr;
} }
if(!FLAC__stream_decoder_set_metadata_respond(sd, FLAC__METADATA_TYPE_VORBIS_COMMENT)) if(!FLAC__stream_decoder_set_metadata_respond(sd, FLAC__METADATA_TYPE_VORBIS_COMMENT))
g_debug("FLAC__stream_decoder_set_metadata_respond() has failed"); LogDebug(flac_domain,
"FLAC__stream_decoder_set_metadata_respond() has failed");
return sd; return sd;
} }
...@@ -139,7 +145,7 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd, ...@@ -139,7 +145,7 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
data->total_frames = duration; data->total_frames = duration;
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) { if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
g_warning("problem reading metadata"); LogWarning(flac_domain, "problem reading metadata");
return false; return false;
} }
...@@ -265,7 +271,8 @@ flac_decode_internal(struct decoder * decoder, ...@@ -265,7 +271,8 @@ flac_decode_internal(struct decoder * decoder,
stream_init(flac_dec, &data, is_ogg); stream_init(flac_dec, &data, is_ogg);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(flac_dec); FLAC__stream_decoder_delete(flac_dec);
g_warning("%s", FLAC__StreamDecoderInitStatusString[status]); LogWarning(flac_domain,
FLAC__StreamDecoderInitStatusString[status]);
return; return;
} }
...@@ -299,7 +306,8 @@ oggflac_scan_file(const char *file, ...@@ -299,7 +306,8 @@ oggflac_scan_file(const char *file,
{ {
FlacMetadataChain chain; FlacMetadataChain chain;
if (!chain.ReadOgg(file)) { if (!chain.ReadOgg(file)) {
g_debug("Failed to read OggFLAC tags: %s", FormatDebug(flac_domain,
"Failed to read OggFLAC tags: %s",
chain.GetStatusString()); chain.GetStatusString());
return false; return false;
} }
...@@ -314,7 +322,8 @@ oggflac_scan_stream(struct input_stream *is, ...@@ -314,7 +322,8 @@ oggflac_scan_stream(struct input_stream *is,
{ {
FlacMetadataChain chain; FlacMetadataChain chain;
if (!chain.ReadOgg(is)) { if (!chain.ReadOgg(is)) {
g_debug("Failed to read OggFLAC tags: %s", FormatDebug(flac_domain,
"Failed to read OggFLAC tags: %s",
chain.GetStatusString()); chain.GetStatusString());
return false; return false;
} }
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "config.h"
#include "FlacDomain.hxx"
#include "util/Domain.hxx"
const Domain flac_domain("flac");
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_FLAC_DOMAIN_HXX
#define MPD_FLAC_DOMAIN_HXX
#include "check.h"
extern const class Domain flac_domain;
#endif
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
#include "config.h" #include "config.h"
#include "FlacInput.hxx" #include "FlacInput.hxx"
#include "FlacDomain.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include "gcc.h" #include "gcc.h"
FLAC__StreamDecoderReadStatus FLAC__StreamDecoderReadStatus
...@@ -49,8 +51,10 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset) ...@@ -49,8 +51,10 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error error; ::Error error;
if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error)) if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error)) {
LogError(error);
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
return FLAC__STREAM_DECODER_SEEK_STATUS_OK; return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
} }
...@@ -89,7 +93,8 @@ FlacInput::Error(FLAC__StreamDecoderErrorStatus status) ...@@ -89,7 +93,8 @@ FlacInput::Error(FLAC__StreamDecoderErrorStatus status)
{ {
if (decoder == nullptr || if (decoder == nullptr ||
decoder_get_command(decoder) != DecoderCommand::STOP) decoder_get_command(decoder) != DecoderCommand::STOP)
g_warning("%s", FLAC__StreamDecoderErrorStatusString[status]); LogWarning(flac_domain,
FLAC__StreamDecoderErrorStatusString[status]);
} }
FLAC__StreamDecoderReadStatus FLAC__StreamDecoderReadStatus
......
...@@ -22,13 +22,14 @@ ...@@ -22,13 +22,14 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <fluidsynth.h> #include <fluidsynth.h>
#undef G_LOG_DOMAIN static constexpr Domain fluidsynth_domain("fluidsynth");
#define G_LOG_DOMAIN "fluidsynth"
static unsigned sample_rate; static unsigned sample_rate;
static const char *soundfont_path; static const char *soundfont_path;
...@@ -36,27 +37,27 @@ static const char *soundfont_path; ...@@ -36,27 +37,27 @@ static const char *soundfont_path;
/** /**
* Convert a fluidsynth log level to a GLib log level. * Convert a fluidsynth log level to a GLib log level.
*/ */
static GLogLevelFlags static LogLevel
fluidsynth_level_to_glib(enum fluid_log_level level) fluidsynth_level_to_mpd(enum fluid_log_level level)
{ {
switch (level) { switch (level) {
case FLUID_PANIC: case FLUID_PANIC:
case FLUID_ERR: case FLUID_ERR:
return G_LOG_LEVEL_CRITICAL; return LogLevel::ERROR;
case FLUID_WARN: case FLUID_WARN:
return G_LOG_LEVEL_WARNING; return LogLevel::WARNING;
case FLUID_INFO: case FLUID_INFO:
return G_LOG_LEVEL_INFO; return LogLevel::INFO;
case FLUID_DBG: case FLUID_DBG:
case LAST_LOG_LEVEL: case LAST_LOG_LEVEL:
return G_LOG_LEVEL_DEBUG; return LogLevel::DEBUG;
} }
/* invalid fluidsynth log level */ /* invalid fluidsynth log level */
return G_LOG_LEVEL_MESSAGE; return LogLevel::INFO;
} }
/** /**
...@@ -66,8 +67,9 @@ fluidsynth_level_to_glib(enum fluid_log_level level) ...@@ -66,8 +67,9 @@ fluidsynth_level_to_glib(enum fluid_log_level level)
static void static void
fluidsynth_mpd_log_function(int level, char *message, gcc_unused void *data) fluidsynth_mpd_log_function(int level, char *message, gcc_unused void *data)
{ {
g_log(G_LOG_DOMAIN, fluidsynth_level_to_glib(fluid_log_level(level)), Log(fluidsynth_domain,
"%s", message); fluidsynth_level_to_mpd(fluid_log_level(level)),
message);
} }
static bool static bool
...@@ -77,7 +79,7 @@ fluidsynth_init(const config_param &param) ...@@ -77,7 +79,7 @@ fluidsynth_init(const config_param &param)
sample_rate = param.GetBlockValue("sample_rate", 48000u); sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, error)) { if (!audio_check_sample_rate(sample_rate, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
...@@ -125,7 +127,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -125,7 +127,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_synth_sfload(synth, soundfont_path, true); ret = fluid_synth_sfload(synth, soundfont_path, true);
if (ret < 0) { if (ret < 0) {
g_warning("fluid_synth_sfload() failed"); LogWarning(fluidsynth_domain, "fluid_synth_sfload() failed");
delete_fluid_synth(synth); delete_fluid_synth(synth);
delete_fluid_settings(settings); delete_fluid_settings(settings);
return; return;
...@@ -142,7 +144,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -142,7 +144,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_player_add(player, path_fs); ret = fluid_player_add(player, path_fs);
if (ret != 0) { if (ret != 0) {
g_warning("fluid_player_add() failed"); LogWarning(fluidsynth_domain, "fluid_player_add() failed");
delete_fluid_player(player); delete_fluid_player(player);
delete_fluid_synth(synth); delete_fluid_synth(synth);
delete_fluid_settings(settings); delete_fluid_settings(settings);
...@@ -153,7 +155,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -153,7 +155,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_player_play(player); ret = fluid_player_play(player);
if (ret != 0) { if (ret != 0) {
g_warning("fluid_player_play() failed"); LogWarning(fluidsynth_domain, "fluid_player_play() failed");
delete_fluid_player(player); delete_fluid_player(player);
delete_fluid_synth(synth); delete_fluid_synth(synth);
delete_fluid_settings(settings); delete_fluid_settings(settings);
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
...@@ -32,11 +34,10 @@ ...@@ -32,11 +34,10 @@
#include <gme/gme.h> #include <gme/gme.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gme"
#define SUBTUNE_PREFIX "tune_" #define SUBTUNE_PREFIX "tune_"
static constexpr Domain gme_domain("gme");
static constexpr unsigned GME_SAMPLE_RATE = 44100; static constexpr unsigned GME_SAMPLE_RATE = 44100;
static constexpr unsigned GME_CHANNELS = 2; static constexpr unsigned GME_CHANNELS = 2;
static constexpr unsigned GME_BUFFER_FRAMES = 2048; static constexpr unsigned GME_BUFFER_FRAMES = 2048;
...@@ -106,7 +107,7 @@ gme_container_scan(const char *path_fs, const unsigned int tnum) ...@@ -106,7 +107,7 @@ gme_container_scan(const char *path_fs, const unsigned int tnum)
Music_Emu *emu; Music_Emu *emu;
const char *gme_err = gme_open_file(path_fs, &emu, GME_SAMPLE_RATE); const char *gme_err = gme_open_file(path_fs, &emu, GME_SAMPLE_RATE);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
return nullptr; return nullptr;
} }
...@@ -134,7 +135,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -134,7 +135,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
gme_open_file(path_container, &emu, GME_SAMPLE_RATE); gme_open_file(path_container, &emu, GME_SAMPLE_RATE);
g_free(path_container); g_free(path_container);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
return; return;
} }
...@@ -142,7 +143,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -142,7 +143,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
const int song_num = get_song_num(path_fs); const int song_num = get_song_num(path_fs);
gme_err = gme_track_info(emu, &ti, song_num); gme_err = gme_track_info(emu, &ti, song_num);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
gme_delete(emu); gme_delete(emu);
return; return;
} }
...@@ -158,7 +159,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -158,7 +159,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
if (!audio_format_init_checked(audio_format, GME_SAMPLE_RATE, if (!audio_format_init_checked(audio_format, GME_SAMPLE_RATE,
SampleFormat::S16, GME_CHANNELS, SampleFormat::S16, GME_CHANNELS,
error)) { error)) {
g_warning("%s", error.GetMessage()); LogError(error);
gme_free_info(ti); gme_free_info(ti);
gme_delete(emu); gme_delete(emu);
return; return;
...@@ -168,7 +169,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -168,7 +169,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
gme_err = gme_start_track(emu, song_num); gme_err = gme_start_track(emu, song_num);
if (gme_err != nullptr) if (gme_err != nullptr)
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
if (ti->length > 0) if (ti->length > 0)
gme_set_fade(emu, ti->length); gme_set_fade(emu, ti->length);
...@@ -179,7 +180,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -179,7 +180,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
short buf[GME_BUFFER_SAMPLES]; short buf[GME_BUFFER_SAMPLES];
gme_err = gme_play(emu, GME_BUFFER_SAMPLES, buf); gme_err = gme_play(emu, GME_BUFFER_SAMPLES, buf);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
return; return;
} }
...@@ -188,7 +189,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -188,7 +189,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
float where = decoder_seek_where(decoder); float where = decoder_seek_where(decoder);
gme_err = gme_seek(emu, int(where * 1000)); gme_err = gme_seek(emu, int(where * 1000));
if (gme_err != nullptr) if (gme_err != nullptr)
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
decoder_command_finished(decoder); decoder_command_finished(decoder);
} }
...@@ -211,7 +212,7 @@ gme_scan_file(const char *path_fs, ...@@ -211,7 +212,7 @@ gme_scan_file(const char *path_fs,
gme_open_file(path_container, &emu, GME_SAMPLE_RATE); gme_open_file(path_container, &emu, GME_SAMPLE_RATE);
g_free(path_container); g_free(path_container);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
return false; return false;
} }
...@@ -220,7 +221,7 @@ gme_scan_file(const char *path_fs, ...@@ -220,7 +221,7 @@ gme_scan_file(const char *path_fs,
gme_info_t *ti; gme_info_t *ti;
gme_err = gme_track_info(emu, &ti, song_num); gme_err = gme_track_info(emu, &ti, song_num);
if (gme_err != nullptr) { if (gme_err != nullptr) {
g_warning("%s", gme_err); LogWarning(gme_domain, gme_err);
gme_delete(emu); gme_delete(emu);
return false; return false;
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
...@@ -40,9 +42,6 @@ ...@@ -40,9 +42,6 @@
#include <id3tag.h> #include <id3tag.h>
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mad"
#define FRAMES_CUSHION 2000 #define FRAMES_CUSHION 2000
#define READ_BUFFER_SIZE 40960 #define READ_BUFFER_SIZE 40960
...@@ -65,6 +64,8 @@ enum muteframe { ...@@ -65,6 +64,8 @@ enum muteframe {
#define DEFAULT_GAPLESS_MP3_PLAYBACK true #define DEFAULT_GAPLESS_MP3_PLAYBACK true
static constexpr Domain mad_domain("mad");
static bool gapless_playback; static bool gapless_playback;
static inline int32_t static inline int32_t
...@@ -367,7 +368,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag) ...@@ -367,7 +368,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
} }
if (count != tagsize) { if (count != tagsize) {
g_debug("error parsing ID3 tag"); LogDebug(mad_domain, "error parsing ID3 tag");
g_free(allocated); g_free(allocated);
return; return;
} }
...@@ -482,8 +483,8 @@ MadDecoder::DecodeNextFrameHeader(Tag **tag) ...@@ -482,8 +483,8 @@ MadDecoder::DecodeNextFrameHeader(Tag **tag)
if (stream.error == MAD_ERROR_BUFLEN) if (stream.error == MAD_ERROR_BUFLEN)
return DECODE_CONT; return DECODE_CONT;
else { else {
g_warning("unrecoverable frame level error " FormatWarning(mad_domain,
"(%s).\n", "unrecoverable frame level error: %s",
mad_stream_errorstr(&stream)); mad_stream_errorstr(&stream));
return DECODE_BREAK; return DECODE_BREAK;
} }
...@@ -529,8 +530,8 @@ MadDecoder::DecodeNextFrame() ...@@ -529,8 +530,8 @@ MadDecoder::DecodeNextFrame()
if (stream.error == MAD_ERROR_BUFLEN) if (stream.error == MAD_ERROR_BUFLEN)
return DECODE_CONT; return DECODE_CONT;
else { else {
g_warning("unrecoverable frame level error " FormatWarning(mad_domain,
"(%s).\n", "unrecoverable frame level error: %s",
mad_stream_errorstr(&stream)); mad_stream_errorstr(&stream));
return DECODE_BREAK; return DECODE_BREAK;
} }
...@@ -702,7 +703,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -702,7 +703,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
&lame->version.major, &lame->version.minor) != 2) &lame->version.major, &lame->version.minor) != 2)
return false; return false;
g_debug("detected LAME version %i.%i (\"%s\")\n", FormatDebug(mad_domain, "detected LAME version %i.%i (\"%s\")",
lame->version.major, lame->version.minor, lame->encoder); lame->version.major, lame->version.minor, lame->encoder);
/* The reference volume was changed from the 83dB used in the /* The reference volume was changed from the 83dB used in the
...@@ -719,7 +720,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -719,7 +720,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
mad_bit_read(ptr, 16); mad_bit_read(ptr, 16);
lame->peak = mad_f_todouble(mad_bit_read(ptr, 32) << 5); /* peak */ lame->peak = mad_f_todouble(mad_bit_read(ptr, 32) << 5); /* peak */
g_debug("LAME peak found: %f\n", lame->peak); FormatDebug(mad_domain, "LAME peak found: %f", lame->peak);
lame->track_gain = 0; lame->track_gain = 0;
name = mad_bit_read(ptr, 3); /* gain name */ name = mad_bit_read(ptr, 3); /* gain name */
...@@ -728,7 +729,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -728,7 +729,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
gain = mad_bit_read(ptr, 9); /* gain*10 */ gain = mad_bit_read(ptr, 9); /* gain*10 */
if (gain && name == 1 && orig != 0) { if (gain && name == 1 && orig != 0) {
lame->track_gain = ((sign ? -gain : gain) / 10.0) + adj; lame->track_gain = ((sign ? -gain : gain) / 10.0) + adj;
g_debug("LAME track gain found: %f\n", lame->track_gain); FormatDebug(mad_domain, "LAME track gain found: %f",
lame->track_gain);
} }
/* tmz reports that this isn't currently written by any version of lame /* tmz reports that this isn't currently written by any version of lame
...@@ -743,7 +745,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -743,7 +745,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
gain = mad_bit_read(ptr, 9); /* gain*10 */ gain = mad_bit_read(ptr, 9); /* gain*10 */
if (gain && name == 2 && orig != 0) { if (gain && name == 2 && orig != 0) {
lame->album_gain = ((sign ? -gain : gain) / 10.0) + adj; lame->album_gain = ((sign ? -gain : gain) / 10.0) + adj;
g_debug("LAME album gain found: %f\n", lame->track_gain); FormatDebug(mad_domain, "LAME album gain found: %f",
lame->track_gain);
} }
#else #else
mad_bit_read(ptr, 16); mad_bit_read(ptr, 16);
...@@ -754,7 +757,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -754,7 +757,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
lame->encoder_delay = mad_bit_read(ptr, 12); lame->encoder_delay = mad_bit_read(ptr, 12);
lame->encoder_padding = mad_bit_read(ptr, 12); lame->encoder_padding = mad_bit_read(ptr, 12);
g_debug("encoder delay is %i, encoder padding is %i\n", FormatDebug(mad_domain, "encoder delay is %i, encoder padding is %i",
lame->encoder_delay, lame->encoder_padding); lame->encoder_delay, lame->encoder_padding);
mad_bit_read(ptr, 80); mad_bit_read(ptr, 80);
...@@ -880,7 +883,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag) ...@@ -880,7 +883,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
return false; return false;
if (max_frames > 8 * 1024 * 1024) { if (max_frames > 8 * 1024 * 1024) {
g_warning("mp3 file header indicates too many frames: %lu\n", FormatWarning(mad_domain,
"mp3 file header indicates too many frames: %lu",
max_frames); max_frames);
return false; return false;
} }
...@@ -1120,8 +1124,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) ...@@ -1120,8 +1124,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
delete tag; delete tag;
if (decoder_get_command(decoder) == DecoderCommand::NONE) if (decoder_get_command(decoder) == DecoderCommand::NONE)
g_warning LogError(mad_domain,
("Input does not appear to be a mp3 bit stream.\n"); "Input does not appear to be a mp3 bit stream");
return; return;
} }
...@@ -1132,7 +1136,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) ...@@ -1132,7 +1136,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
SampleFormat::S24_P32, SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header), MAD_NCHANNELS(&data.frame.header),
error)) { error)) {
g_warning("%s", error.GetMessage()); LogError(error);
delete tag; delete tag;
return; return;
} }
......
...@@ -22,13 +22,14 @@ ...@@ -22,13 +22,14 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <mikmod.h> #include <mikmod.h>
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN static constexpr Domain mikmod_domain("mikmod");
#define G_LOG_DOMAIN "mikmod"
/* this is largely copied from alsaplayer */ /* this is largely copied from alsaplayer */
...@@ -127,7 +128,8 @@ mikmod_decoder_init(const config_param &param) ...@@ -127,7 +128,8 @@ mikmod_decoder_init(const config_param &param)
DMODE_16BITS); DMODE_16BITS);
if (MikMod_Init(params)) { if (MikMod_Init(params)) {
g_warning("Could not init MikMod: %s\n", FormatError(mikmod_domain,
"Could not init MikMod: %s",
MikMod_strerror(MikMod_errno)); MikMod_strerror(MikMod_errno));
return false; return false;
} }
...@@ -154,7 +156,8 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -154,7 +156,8 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
g_free(path2); g_free(path2);
if (handle == nullptr) { if (handle == nullptr) {
g_warning("failed to open mod: %s", path_fs); FormatError(mikmod_domain,
"failed to open mod: %s", path_fs);
return; return;
} }
...@@ -187,7 +190,8 @@ mikmod_decoder_scan_file(const char *path_fs, ...@@ -187,7 +190,8 @@ mikmod_decoder_scan_file(const char *path_fs,
if (handle == nullptr) { if (handle == nullptr) {
g_free(path2); g_free(path2);
g_debug("Failed to open file: %s", path_fs); FormatDebug(mikmod_domain,
"Failed to open file: %s", path_fs);
return false; return false;
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <libmodplug/modplug.h> #include <libmodplug/modplug.h>
...@@ -29,8 +31,7 @@ ...@@ -29,8 +31,7 @@
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN static constexpr Domain modplug_domain("modplug");
#define G_LOG_DOMAIN "modplug"
static constexpr size_t MODPLUG_FRAME_SIZE = 4096; static constexpr size_t MODPLUG_FRAME_SIZE = 4096;
static constexpr size_t MODPLUG_PREALLOC_BLOCK = 256 * 1024; static constexpr size_t MODPLUG_PREALLOC_BLOCK = 256 * 1024;
...@@ -43,12 +44,12 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is) ...@@ -43,12 +44,12 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
const goffset size = is->GetSize(); const goffset size = is->GetSize();
if (size == 0) { if (size == 0) {
g_warning("file is empty"); LogWarning(modplug_domain, "file is empty");
return nullptr; return nullptr;
} }
if (size > MODPLUG_FILE_LIMIT) { if (size > MODPLUG_FILE_LIMIT) {
g_warning("file too large"); LogWarning(modplug_domain, "file too large");
return nullptr; return nullptr;
} }
...@@ -77,7 +78,7 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is) ...@@ -77,7 +78,7 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
} }
if (goffset(bdatas->len + ret) > MODPLUG_FILE_LIMIT) { if (goffset(bdatas->len + ret) > MODPLUG_FILE_LIMIT) {
g_warning("stream too large\n"); LogWarning(modplug_domain, "stream too large");
g_free(data); g_free(data);
g_byte_array_free(bdatas, TRUE); g_byte_array_free(bdatas, TRUE);
return nullptr; return nullptr;
...@@ -103,7 +104,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) ...@@ -103,7 +104,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
bdatas = mod_loadfile(decoder, is); bdatas = mod_loadfile(decoder, is);
if (!bdatas) { if (!bdatas) {
g_warning("could not load stream\n"); LogWarning(modplug_domain, "could not load stream");
return; return;
} }
...@@ -119,7 +120,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) ...@@ -119,7 +120,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
f = ModPlug_Load(bdatas->data, bdatas->len); f = ModPlug_Load(bdatas->data, bdatas->len);
g_byte_array_free(bdatas, TRUE); g_byte_array_free(bdatas, TRUE);
if (!f) { if (!f) {
g_warning("could not decode stream\n"); LogWarning(modplug_domain, "could not decode stream");
return; return;
} }
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <mpc/mpcdec.h> #include <mpc/mpcdec.h>
...@@ -32,14 +34,13 @@ ...@@ -32,14 +34,13 @@
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mpcdec"
struct mpc_decoder_data { struct mpc_decoder_data {
struct input_stream *is; struct input_stream *is;
struct decoder *decoder; struct decoder *decoder;
}; };
static constexpr Domain mpcdec_domain("mpcdec");
static mpc_int32_t static mpc_int32_t
mpc_read_cb(mpc_reader *reader, void *ptr, mpc_int32_t size) mpc_read_cb(mpc_reader *reader, void *ptr, mpc_int32_t size)
{ {
...@@ -148,7 +149,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -148,7 +149,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
mpc_demux *demux = mpc_demux_init(&reader); mpc_demux *demux = mpc_demux_init(&reader);
if (demux == nullptr) { if (demux == nullptr) {
if (decoder_get_command(mpd_decoder) != DecoderCommand::STOP) if (decoder_get_command(mpd_decoder) != DecoderCommand::STOP)
g_warning("Not a valid musepack stream"); LogWarning(mpcdec_domain,
"Not a valid musepack stream");
return; return;
} }
...@@ -160,7 +162,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -160,7 +162,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, info.sample_freq, if (!audio_format_init_checked(audio_format, info.sample_freq,
SampleFormat::S24_P32, SampleFormat::S24_P32,
info.channels, error)) { info.channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
mpc_demux_exit(demux); mpc_demux_exit(demux);
return; return;
} }
...@@ -199,7 +201,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -199,7 +201,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
frame.buffer = (MPC_SAMPLE_FORMAT *)sample_buffer; frame.buffer = (MPC_SAMPLE_FORMAT *)sample_buffer;
mpc_status status = mpc_demux_decode(demux, &frame); mpc_status status = mpc_demux_decode(demux, &frame);
if (status != MPC_STATUS_OK) { if (status != MPC_STATUS_OK) {
g_warning("Failed to decode sample"); LogWarning(mpcdec_domain,
"Failed to decode sample");
break; break;
} }
......
...@@ -23,14 +23,15 @@ ...@@ -23,14 +23,15 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <mpg123.h> #include <mpg123.h>
#include <stdio.h> #include <stdio.h>
#undef G_LOG_DOMAIN static constexpr Domain mpg123_domain("mpg123");
#define G_LOG_DOMAIN "mpg123"
static bool static bool
mpd_mpg123_init(gcc_unused const config_param &param) mpd_mpg123_init(gcc_unused const config_param &param)
...@@ -70,7 +71,8 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs, ...@@ -70,7 +71,8 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
error = mpg123_open(handle, path_dup); error = mpg123_open(handle, path_dup);
g_free(path_dup); g_free(path_dup);
if (error != MPG123_OK) { if (error != MPG123_OK) {
g_warning("libmpg123 failed to open %s: %s", FormatWarning(mpg123_domain,
"libmpg123 failed to open %s: %s",
path_fs, mpg123_plain_strerror(error)); path_fs, mpg123_plain_strerror(error));
return false; return false;
} }
...@@ -79,21 +81,24 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs, ...@@ -79,21 +81,24 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
error = mpg123_getformat(handle, &rate, &channels, &encoding); error = mpg123_getformat(handle, &rate, &channels, &encoding);
if (error != MPG123_OK) { if (error != MPG123_OK) {
g_warning("mpg123_getformat() failed: %s", FormatWarning(mpg123_domain,
"mpg123_getformat() failed: %s",
mpg123_plain_strerror(error)); mpg123_plain_strerror(error));
return false; return false;
} }
if (encoding != MPG123_ENC_SIGNED_16) { if (encoding != MPG123_ENC_SIGNED_16) {
/* other formats not yet implemented */ /* other formats not yet implemented */
g_warning("expected MPG123_ENC_SIGNED_16, got %d", encoding); FormatWarning(mpg123_domain,
"expected MPG123_ENC_SIGNED_16, got %d",
encoding);
return false; return false;
} }
Error error2; Error error2;
if (!audio_format_init_checked(audio_format, rate, SampleFormat::S16, if (!audio_format_init_checked(audio_format, rate, SampleFormat::S16,
channels, error2)) { channels, error2)) {
g_warning("%s", error2.GetMessage()); LogError(error2);
return false; return false;
} }
...@@ -112,7 +117,8 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -112,7 +117,8 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
handle = mpg123_new(nullptr, &error); handle = mpg123_new(nullptr, &error);
if (handle == nullptr) { if (handle == nullptr) {
g_warning("mpg123_new() failed: %s", FormatError(mpg123_domain,
"mpg123_new() failed: %s",
mpg123_plain_strerror(error)); mpg123_plain_strerror(error));
return; return;
} }
...@@ -158,7 +164,8 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -158,7 +164,8 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
error = mpg123_read(handle, buffer, sizeof(buffer), &nbytes); error = mpg123_read(handle, buffer, sizeof(buffer), &nbytes);
if (error != MPG123_OK) { if (error != MPG123_OK) {
if (error != MPG123_DONE) if (error != MPG123_DONE)
g_warning("mpg123_read() failed: %s", FormatWarning(mpg123_domain,
"mpg123_read() failed: %s",
mpg123_plain_strerror(error)); mpg123_plain_strerror(error));
break; break;
} }
...@@ -204,7 +211,8 @@ mpd_mpg123_scan_file(const char *path_fs, ...@@ -204,7 +211,8 @@ mpd_mpg123_scan_file(const char *path_fs,
handle = mpg123_new(nullptr, &error); handle = mpg123_new(nullptr, &error);
if (handle == nullptr) { if (handle == nullptr) {
g_warning("mpg123_new() failed: %s", FormatError(mpg123_domain,
"mpg123_new() failed: %s",
mpg123_plain_strerror(error)); mpg123_plain_strerror(error));
return false; return false;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "OpusDecoderPlugin.h" #include "OpusDecoderPlugin.h"
#include "OpusDomain.hxx"
#include "OpusHead.hxx" #include "OpusHead.hxx"
#include "OpusTags.hxx" #include "OpusTags.hxx"
#include "OggUtil.hxx" #include "OggUtil.hxx"
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#include "tag/TagBuilder.hxx" #include "tag/TagBuilder.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <opus.h> #include <opus.h>
#include <ogg/ogg.h> #include <ogg/ogg.h>
...@@ -40,9 +42,6 @@ ...@@ -40,9 +42,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "opus"
static const opus_int32 opus_sample_rate = 48000; static const opus_int32 opus_sample_rate = 48000;
gcc_pure gcc_pure
...@@ -62,7 +61,7 @@ IsOpusTags(const ogg_packet &packet) ...@@ -62,7 +61,7 @@ IsOpusTags(const ogg_packet &packet)
static bool static bool
mpd_opus_init(gcc_unused const config_param &param) mpd_opus_init(gcc_unused const config_param &param)
{ {
g_debug("%s", opus_get_version_string()); LogDebug(opus_domain, opus_get_version_string());
return true; return true;
} }
...@@ -199,7 +198,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) ...@@ -199,7 +198,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
opus_decoder = opus_decoder_create(opus_sample_rate, channels, opus_decoder = opus_decoder_create(opus_sample_rate, channels,
&opus_error); &opus_error);
if (opus_decoder == nullptr) { if (opus_decoder == nullptr) {
g_warning("libopus error: %s", FormatError(opus_domain, "libopus error: %s",
opus_strerror(opus_error)); opus_strerror(opus_error));
return DecoderCommand::STOP; return DecoderCommand::STOP;
} }
...@@ -249,7 +248,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) ...@@ -249,7 +248,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
output_buffer, output_size, output_buffer, output_size,
0); 0);
if (nframes < 0) { if (nframes < 0) {
g_warning("%s", opus_strerror(nframes)); LogError(opus_domain, opus_strerror(nframes));
return DecoderCommand::STOP; return DecoderCommand::STOP;
} }
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "config.h"
#include "OpusDomain.hxx"
#include "util/Domain.hxx"
const Domain opus_domain("opus");
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_OPUS_DOMAIN_HXX
#define MPD_OPUS_DOMAIN_HXX
#include "check.h"
extern const class Domain opus_domain;
#endif
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
extern "C" { extern "C" {
#include "util/byte_reverse.h" #include "util/byte_reverse.h"
...@@ -32,9 +33,6 @@ extern "C" { ...@@ -32,9 +33,6 @@ extern "C" {
#include <string.h> #include <string.h>
#include <stdio.h> /* for SEEK_SET */ #include <stdio.h> /* for SEEK_SET */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static void static void
pcm_stream_decode(struct decoder *decoder, struct input_stream *is) pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
{ {
...@@ -86,7 +84,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -86,7 +84,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
if (is->LockSeek(offset, SEEK_SET, error)) { if (is->LockSeek(offset, SEEK_SET, error)) {
decoder_command_finished(decoder); decoder_command_finished(decoder);
} else { } else {
g_warning("seeking failed: %s", error.GetMessage()); LogError(error);
decoder_seek_error(decoder); decoder_seek_error(decoder);
} }
......
...@@ -24,11 +24,12 @@ ...@@ -24,11 +24,12 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <sndfile.h> #include <sndfile.h>
#undef G_LOG_DOMAIN static constexpr Domain sndfile_domain("sndfile");
#define G_LOG_DOMAIN "sndfile"
static sf_count_t static sf_count_t
sndfile_vio_get_filelen(void *user_data) sndfile_vio_get_filelen(void *user_data)
...@@ -57,7 +58,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data) ...@@ -57,7 +58,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
Error error; Error error;
size_t nbytes = is->LockRead(ptr, count, error); size_t nbytes = is->LockRead(ptr, count, error);
if (nbytes == 0 && error.IsDefined()) { if (nbytes == 0 && error.IsDefined()) {
g_warning("%s", error.GetMessage()); LogError(error);
return -1; return -1;
} }
...@@ -124,7 +125,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -124,7 +125,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
sf = sf_open_virtual(&vio, SFM_READ, &info, is); sf = sf_open_virtual(&vio, SFM_READ, &info, is);
if (sf == nullptr) { if (sf == nullptr) {
g_warning("sf_open_virtual() failed"); LogWarning(sndfile_domain, "sf_open_virtual() failed");
return; return;
} }
...@@ -136,7 +137,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -136,7 +137,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, info.samplerate, if (!audio_format_init_checked(audio_format, info.samplerate,
SampleFormat::S32, SampleFormat::S32,
info.channels, error)) { info.channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
...@@ -187,7 +188,8 @@ sndfile_scan_file(const char *path_fs, ...@@ -187,7 +188,8 @@ sndfile_scan_file(const char *path_fs,
if (!audio_valid_sample_rate(info.samplerate)) { if (!audio_valid_sample_rate(info.samplerate)) {
sf_close(sf); sf_close(sf);
g_warning("Invalid sample rate in %s\n", path_fs); FormatWarning(sndfile_domain,
"Invalid sample rate in %s", path_fs);
return false; return false;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "VorbisDecoderPlugin.h" #include "VorbisDecoderPlugin.h"
#include "VorbisComments.hxx" #include "VorbisComments.hxx"
#include "VorbisDomain.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "OggCodec.hxx" #include "OggCodec.hxx"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "Log.hxx"
#ifndef HAVE_TREMOR #ifndef HAVE_TREMOR
#define OV_EXCLUDE_STATIC_CALLBACKS #define OV_EXCLUDE_STATIC_CALLBACKS
...@@ -50,9 +52,6 @@ ...@@ -50,9 +52,6 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "vorbis"
#if G_BYTE_ORDER == G_BIG_ENDIAN #if G_BYTE_ORDER == G_BIG_ENDIAN
#define VORBIS_BIG_ENDIAN true #define VORBIS_BIG_ENDIAN true
#else #else
...@@ -144,7 +143,8 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf, ...@@ -144,7 +143,8 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
if (ret < 0) { if (ret < 0) {
if (decoder == NULL || if (decoder == NULL ||
decoder_get_command(decoder) == DecoderCommand::NONE) decoder_get_command(decoder) == DecoderCommand::NONE)
g_warning("Failed to open Ogg Vorbis stream: %s", FormatWarning(vorbis_domain,
"Failed to open Ogg Vorbis stream: %s",
vorbis_strerror(ret)); vorbis_strerror(ret));
return false; return false;
} }
...@@ -198,7 +198,7 @@ vorbis_stream_decode(struct decoder *decoder, ...@@ -198,7 +198,7 @@ vorbis_stream_decode(struct decoder *decoder,
const vorbis_info *vi = ov_info(&vf, -1); const vorbis_info *vi = ov_info(&vf, -1);
if (vi == NULL) { if (vi == NULL) {
g_warning("ov_info() has failed"); LogWarning(vorbis_domain, "ov_info() has failed");
return; return;
} }
...@@ -211,7 +211,7 @@ vorbis_stream_decode(struct decoder *decoder, ...@@ -211,7 +211,7 @@ vorbis_stream_decode(struct decoder *decoder,
SampleFormat::FLOAT, SampleFormat::FLOAT,
#endif #endif
vi->channels, error)) { vi->channels, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
...@@ -272,7 +272,8 @@ vorbis_stream_decode(struct decoder *decoder, ...@@ -272,7 +272,8 @@ vorbis_stream_decode(struct decoder *decoder,
if (current_section != prev_section) { if (current_section != prev_section) {
vi = ov_info(&vf, -1); vi = ov_info(&vf, -1);
if (vi == NULL) { if (vi == NULL) {
g_warning("ov_info() has failed"); LogWarning(vorbis_domain,
"ov_info() has failed");
break; break;
} }
...@@ -280,7 +281,8 @@ vorbis_stream_decode(struct decoder *decoder, ...@@ -280,7 +281,8 @@ vorbis_stream_decode(struct decoder *decoder,
vi->channels != (int)audio_format.channels) { vi->channels != (int)audio_format.channels) {
/* we don't support audio format /* we don't support audio format
change yet */ change yet */
g_warning("audio format change, stopping here"); LogWarning(vorbis_domain,
"audio format change, stopping here");
break; break;
} }
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#include "config.h"
#include "VorbisDomain.hxx"
#include "util/Domain.hxx"
const Domain vorbis_domain("vorbis");
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_VORBIS_DOMAIN_HXX
#define MPD_VORBIS_DOMAIN_HXX
#include "check.h"
extern const class Domain vorbis_domain;
#endif
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "tag/ApeTag.hxx" #include "tag/ApeTag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <wavpack/wavpack.h> #include <wavpack/wavpack.h>
#include <glib.h> #include <glib.h>
...@@ -33,11 +35,10 @@ ...@@ -33,11 +35,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "wavpack"
#define ERRORLEN 80 #define ERRORLEN 80
static constexpr Domain wavpack_domain("wavpack");
/** A pointer type for format converter function. */ /** A pointer type for format converter function. */
typedef void (*format_samples_t)( typedef void (*format_samples_t)(
int bytes_per_sample, int bytes_per_sample,
...@@ -155,7 +156,7 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek) ...@@ -155,7 +156,7 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
WavpackGetSampleRate(wpc), WavpackGetSampleRate(wpc),
sample_format, sample_format,
WavpackGetNumChannels(wpc), error)) { WavpackGetNumChannels(wpc), error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
...@@ -294,10 +295,9 @@ wavpack_scan_file(const char *fname, ...@@ -294,10 +295,9 @@ wavpack_scan_file(const char *fname,
wpc = WavpackOpenFileInput(fname, error, OPEN_TAGS, 0); wpc = WavpackOpenFileInput(fname, error, OPEN_TAGS, 0);
if (wpc == NULL) { if (wpc == NULL) {
g_warning( FormatError(wavpack_domain,
"failed to open WavPack file \"%s\": %s\n", "failed to open WavPack file \"%s\": %s",
fname, error fname, error);
);
return false; return false;
} }
...@@ -532,7 +532,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) ...@@ -532,7 +532,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
); );
if (wpc == NULL) { if (wpc == NULL) {
g_warning("failed to open WavPack stream: %s\n", error); FormatError(wavpack_domain,
"failed to open WavPack stream: %s", error);
return; return;
} }
...@@ -558,10 +559,9 @@ wavpack_filedecode(struct decoder *decoder, const char *fname) ...@@ -558,10 +559,9 @@ wavpack_filedecode(struct decoder *decoder, const char *fname)
OPEN_TAGS | OPEN_WVC | OPEN_NORMALIZE, 23 OPEN_TAGS | OPEN_WVC | OPEN_NORMALIZE, 23
); );
if (wpc == NULL) { if (wpc == NULL) {
g_warning( FormatWarning(wavpack_domain,
"failed to open WavPack file \"%s\": %s\n", "failed to open WavPack file \"%s\": %s",
fname, error fname, error);
);
return; return;
} }
......
...@@ -22,18 +22,17 @@ ...@@ -22,18 +22,17 @@
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <glib.h>
extern "C" { extern "C" {
#include <wildmidi_lib.h> #include <wildmidi_lib.h>
} }
#undef G_LOG_DOMAIN static constexpr Domain wildmidi_domain("wildmidi");
#define G_LOG_DOMAIN "wildmidi"
static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000; static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000;
...@@ -49,7 +48,9 @@ wildmidi_init(const config_param &param) ...@@ -49,7 +48,9 @@ wildmidi_init(const config_param &param)
if (!FileExists(path)) { if (!FileExists(path)) {
const auto utf8 = path.ToUTF8(); const auto utf8 = path.ToUTF8();
g_debug("configuration file does not exist: %s", utf8.c_str()); FormatDebug(wildmidi_domain,
"configuration file does not exist: %s",
utf8.c_str());
return false; return false;
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "config.h" #include "config.h"
#include "../DecoderAPI.hxx" #include "../DecoderAPI.hxx"
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -30,11 +32,10 @@ ...@@ -30,11 +32,10 @@
#include <sidplay/builders/resid.h> #include <sidplay/builders/resid.h>
#include <sidplay/utils/SidTuneMod.h> #include <sidplay/utils/SidTuneMod.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "sidplay"
#define SUBTUNE_PREFIX "tune_" #define SUBTUNE_PREFIX "tune_"
static constexpr Domain sidplay_domain("sidplay");
static GPatternSpec *path_with_subtune; static GPatternSpec *path_with_subtune;
static const char *songlength_file; static const char *songlength_file;
static GKeyFile *songlength_database; static GKeyFile *songlength_database;
...@@ -52,7 +53,8 @@ sidplay_load_songlength_db(const char *path) ...@@ -52,7 +53,8 @@ sidplay_load_songlength_db(const char *path)
gsize size; gsize size;
if (!g_file_get_contents(path, &data, &size, &error)) { if (!g_file_get_contents(path, &data, &size, &error)) {
g_warning("unable to read songlengths file %s: %s", FormatError(sidplay_domain,
"unable to read songlengths file %s: %s",
path, error->message); path, error->message);
g_error_free(error); g_error_free(error);
return NULL; return NULL;
...@@ -68,7 +70,8 @@ sidplay_load_songlength_db(const char *path) ...@@ -68,7 +70,8 @@ sidplay_load_songlength_db(const char *path)
G_KEY_FILE_NONE, &error); G_KEY_FILE_NONE, &error);
g_free(data); g_free(data);
if (!success) { if (!success) {
g_warning("unable to parse songlengths file %s: %s", FormatError(sidplay_domain,
"unable to parse songlengths file %s: %s",
path, error->message); path, error->message);
g_error_free(error); g_error_free(error);
g_key_file_free(db); g_key_file_free(db);
...@@ -162,7 +165,8 @@ get_song_length(const char *path_fs) ...@@ -162,7 +165,8 @@ get_song_length(const char *path_fs)
SidTuneMod tune(sid_file); SidTuneMod tune(sid_file);
g_free(sid_file); g_free(sid_file);
if(!tune) { if(!tune) {
g_warning("failed to load file for calculating md5 sum"); LogWarning(sidplay_domain,
"failed to load file for calculating md5 sum");
return -1; return -1;
} }
char md5sum[SIDTUNE_MD5_LENGTH+1]; char md5sum[SIDTUNE_MD5_LENGTH+1];
...@@ -205,7 +209,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -205,7 +209,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
SidTune tune(path_container, NULL, true); SidTune tune(path_container, NULL, true);
g_free(path_container); g_free(path_container);
if (!tune) { if (!tune) {
g_warning("failed to load file"); LogWarning(sidplay_domain, "failed to load file");
return; return;
} }
...@@ -220,7 +224,8 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -220,7 +224,8 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
sidplay2 player; sidplay2 player;
int iret = player.load(&tune); int iret = player.load(&tune);
if (iret != 0) { if (iret != 0) {
g_warning("sidplay2.load() failed: %s", player.error()); FormatWarning(sidplay_domain,
"sidplay2.load() failed: %s", player.error());
return; return;
} }
...@@ -228,19 +233,20 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -228,19 +233,20 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
ReSIDBuilder builder("ReSID"); ReSIDBuilder builder("ReSID");
if (!builder) { if (!builder) {
g_warning("failed to initialize ReSIDBuilder"); LogWarning(sidplay_domain,
"failed to initialize ReSIDBuilder");
return; return;
} }
builder.create(player.info().maxsids); builder.create(player.info().maxsids);
if (!builder) { if (!builder) {
g_warning("ReSIDBuilder.create() failed"); LogWarning(sidplay_domain, "ReSIDBuilder.create() failed");
return; return;
} }
builder.filter(filter_setting); builder.filter(filter_setting);
if (!builder) { if (!builder) {
g_warning("ReSIDBuilder.filter() failed"); LogWarning(sidplay_domain, "ReSIDBuilder.filter() failed");
return; return;
} }
...@@ -274,7 +280,8 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) ...@@ -274,7 +280,8 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
iret = player.config(config); iret = player.config(config);
if (iret != 0) { if (iret != 0) {
g_warning("sidplay2.config() failed: %s", player.error()); FormatWarning(sidplay_domain,
"sidplay2.config() failed: %s", player.error());
return; return;
} }
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "opus_encoder"
struct opus_encoder { struct opus_encoder {
/** the base class */ /** the base class */
Encoder encoder; Encoder encoder;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ConfigError.hxx" #include "ConfigError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <twolame.h> #include <twolame.h>
...@@ -109,7 +110,8 @@ TwolameEncoder::Configure(const config_param &param, Error &error) ...@@ -109,7 +110,8 @@ TwolameEncoder::Configure(const config_param &param, Error &error)
static Encoder * static Encoder *
twolame_encoder_init(const config_param &param, Error &error_r) twolame_encoder_init(const config_param &param, Error &error_r)
{ {
g_debug("libtwolame version %s", get_twolame_version()); FormatDebug(twolame_encoder_domain,
"libtwolame version %s", get_twolame_version());
TwolameEncoder *encoder = new TwolameEncoder(); TwolameEncoder *encoder = new TwolameEncoder();
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "vorbis_encoder"
struct vorbis_encoder { struct vorbis_encoder {
/** the base class */ /** the base class */
Encoder encoder; Encoder encoder;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "system/fd_util.h" #include "system/fd_util.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -52,9 +53,6 @@ ...@@ -52,9 +53,6 @@
#include <netdb.h> #include <netdb.h>
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "listen"
#define DEFAULT_PORT 6600 #define DEFAULT_PORT 6600
class OneServerSocket final : private SocketMonitor { class OneServerSocket final : private SocketMonitor {
...@@ -167,13 +165,15 @@ OneServerSocket::Accept() ...@@ -167,13 +165,15 @@ OneServerSocket::Accept()
&peer_address_length); &peer_address_length);
if (peer_fd < 0) { if (peer_fd < 0) {
const SocketErrorMessage msg; const SocketErrorMessage msg;
g_warning("accept() failed: %s", (const char *)msg); FormatError(server_socket_domain,
"accept() failed: %s", (const char *)msg);
return; return;
} }
if (socket_keepalive(peer_fd)) { if (socket_keepalive(peer_fd)) {
const SocketErrorMessage msg; const SocketErrorMessage msg;
g_warning("Could not set TCP keepalive option: %s", FormatError(server_socket_domain,
"Could not set TCP keepalive option: %s",
(const char *)msg); (const char *)msg);
} }
...@@ -241,7 +241,8 @@ ServerSocket::Open(Error &error) ...@@ -241,7 +241,8 @@ ServerSocket::Open(Error &error)
if (good != nullptr && good->GetSerial() == i.GetSerial()) { if (good != nullptr && good->GetSerial() == i.GetSerial()) {
char *address_string = i.ToString(); char *address_string = i.ToString();
char *good_string = good->ToString(); char *good_string = good->ToString();
g_warning("bind to '%s' failed: %s " FormatWarning(server_socket_domain,
"bind to '%s' failed: %s "
"(continuing anyway, because " "(continuing anyway, because "
"binding to '%s' succeeded)", "binding to '%s' succeeded)",
address_string, error2.GetMessage(), address_string, error2.GetMessage(),
......
...@@ -30,14 +30,12 @@ ...@@ -30,14 +30,12 @@
#include "pcm/PcmBuffer.hxx" #include "pcm/PcmBuffer.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain replay_gain_domain("replay_gain");
#define G_LOG_DOMAIN "replay_gain"
class ReplayGainFilter final : public Filter { class ReplayGainFilter final : public Filter {
/** /**
...@@ -105,7 +103,9 @@ public: ...@@ -105,7 +103,9 @@ public:
/* no change */ /* no change */
return; return;
g_debug("replay gain mode has changed %d->%d\n", mode, _mode); FormatDebug(replay_gain_domain,
"replay gain mode has changed %d->%d\n",
mode, _mode);
mode = _mode; mode = _mode;
Update(); Update();
...@@ -122,15 +122,14 @@ public: ...@@ -122,15 +122,14 @@ public:
size_t *dest_size_r, Error &error); size_t *dest_size_r, Error &error);
}; };
static constexpr Domain replay_gain_domain("replay_gain");
void void
ReplayGainFilter::Update() ReplayGainFilter::Update()
{ {
if (mode != REPLAY_GAIN_OFF) { if (mode != REPLAY_GAIN_OFF) {
float scale = replay_gain_tuple_scale(&info.tuples[mode], float scale = replay_gain_tuple_scale(&info.tuples[mode],
replay_gain_preamp, replay_gain_missing_preamp, replay_gain_limit); replay_gain_preamp, replay_gain_missing_preamp, replay_gain_limit);
g_debug("scale=%f\n", (double)scale); FormatDebug(replay_gain_domain,
"scale=%f\n", (double)scale);
volume = pcm_float_to_volume(scale); volume = pcm_float_to_volume(scale);
} else } else
...@@ -145,8 +144,7 @@ ReplayGainFilter::Update() ...@@ -145,8 +144,7 @@ ReplayGainFilter::Update()
Error error; Error error;
if (!mixer_set_volume(mixer, _volume, error)) if (!mixer_set_volume(mixer, _volume, error))
g_warning("Failed to update hardware mixer: %s", LogError(error, "Failed to update hardware mixer");
error.GetMessage());
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include "gcc.h" #include "gcc.h"
#include <glib.h> #include <glib.h>
...@@ -35,9 +36,6 @@ ...@@ -35,9 +36,6 @@
#include <stdio.h> // for sprintf() #include <stdio.h> // for sprintf()
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "path"
/** /**
* Maximal number of bytes required to represent path name in UTF-8 * Maximal number of bytes required to represent path name in UTF-8
* (including nul-terminator). * (including nul-terminator).
...@@ -145,7 +143,8 @@ SetFSCharset(const char *charset) ...@@ -145,7 +143,8 @@ SetFSCharset(const char *charset)
fs_charset = charset; fs_charset = charset;
g_debug("SetFSCharset: fs charset is: %s", fs_charset.c_str()); FormatDebug(path_domain,
"SetFSCharset: fs charset is: %s", fs_charset.c_str());
} }
const std::string &Path::GetFSCharset() const std::string &Path::GetFSCharset()
...@@ -180,7 +179,8 @@ void Path::GlobalInit() ...@@ -180,7 +179,8 @@ void Path::GlobalInit()
if (charset) { if (charset) {
SetFSCharset(charset); SetFSCharset(charset);
} else { } else {
g_message("setting filesystem charset to ISO-8859-1"); LogDebug(path_domain,
"setting filesystem charset to ISO-8859-1");
SetFSCharset("ISO-8859-1"); SetFSCharset("ISO-8859-1");
} }
} }
...@@ -25,9 +25,13 @@ ...@@ -25,9 +25,13 @@
#include "ArchiveFile.hxx" #include "ArchiveFile.hxx"
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
static constexpr Domain archive_domain("archive");
/** /**
* select correct archive plugin to handle the input stream * select correct archive plugin to handle the input stream
* may allow stacking of archive plugins. for example for handling * may allow stacking of archive plugins. for example for handling
...@@ -51,7 +55,8 @@ input_archive_open(const char *pathname, ...@@ -51,7 +55,8 @@ input_archive_open(const char *pathname,
pname = g_strdup(pathname); pname = g_strdup(pathname);
// archive_lookup will modify pname when true is returned // archive_lookup will modify pname when true is returned
if (!archive_lookup(pname, &archive, &filename, &suffix)) { if (!archive_lookup(pname, &archive, &filename, &suffix)) {
g_debug("not an archive, lookup %s failed\n", pname); FormatDebug(archive_domain,
"not an archive, lookup %s failed", pname);
g_free(pname); g_free(pname);
return NULL; return NULL;
} }
...@@ -59,7 +64,8 @@ input_archive_open(const char *pathname, ...@@ -59,7 +64,8 @@ input_archive_open(const char *pathname,
//check which archive plugin to use (by ext) //check which archive plugin to use (by ext)
arplug = archive_plugin_from_suffix(suffix); arplug = archive_plugin_from_suffix(suffix);
if (!arplug) { if (!arplug) {
g_warning("can't handle archive %s\n",archive); FormatWarning(archive_domain,
"can't handle archive %s", archive);
g_free(pname); g_free(pname);
return NULL; return NULL;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
...@@ -195,17 +196,20 @@ input_cdio_open(const char *uri, ...@@ -195,17 +196,20 @@ input_cdio_open(const char *uri,
bool reverse_endian; bool reverse_endian;
switch (data_bigendianp(i->drv)) { switch (data_bigendianp(i->drv)) {
case -1: case -1:
g_debug("cdda: drive returns unknown audio data"); LogDebug(cdio_domain, "drive returns unknown audio data");
reverse_endian = false; reverse_endian = false;
break; break;
case 0: case 0:
g_debug("cdda: drive returns audio data Little Endian."); LogDebug(cdio_domain, "drive returns audio data Little Endian");
reverse_endian = G_BYTE_ORDER == G_BIG_ENDIAN; reverse_endian = G_BYTE_ORDER == G_BIG_ENDIAN;
break; break;
case 1: case 1:
g_debug("cdda: drive returns audio data Big Endian."); LogDebug(cdio_domain, "drive returns audio data Big Endian");
reverse_endian = G_BYTE_ORDER == G_LITTLE_ENDIAN; reverse_endian = G_BYTE_ORDER == G_LITTLE_ENDIAN;
break; break;
default: default:
error.Format(cdio_domain, "Drive returns unknown data type %d", error.Format(cdio_domain, "Drive returns unknown data type %d",
data_bigendianp(i->drv)); data_bigendianp(i->drv));
...@@ -305,7 +309,8 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length, ...@@ -305,7 +309,8 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length,
s_err = cdda_errors(cis->drv); s_err = cdda_errors(cis->drv);
if (s_err) { if (s_err) {
g_warning("paranoia_read: %s", s_err ); FormatError(cdio_domain,
"paranoia_read: %s", s_err);
free(s_err); free(s_err);
} }
s_mess = cdda_messages(cis->drv); s_mess = cdda_messages(cis->drv);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "IOThread.hxx" #include "IOThread.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
...@@ -53,9 +54,6 @@ ...@@ -53,9 +54,6 @@
#error libcurl is too old #error libcurl is too old
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_curl"
/** /**
* Do not buffer more than this number of bytes. It should be a * Do not buffer more than this number of bytes. It should be a
* reasonable limit that doesn't make low-end machines suffer too * reasonable limit that doesn't make low-end machines suffer too
...@@ -297,7 +295,8 @@ CurlSockets::UpdateSockets() ...@@ -297,7 +295,8 @@ CurlSockets::UpdateSockets()
CURLMcode mcode = curl_multi_fdset(curl.multi, &rfds, &wfds, CURLMcode mcode = curl_multi_fdset(curl.multi, &rfds, &wfds,
&efds, &max_fd); &efds, &max_fd);
if (mcode != CURLM_OK) { if (mcode != CURLM_OK) {
g_warning("curl_multi_fdset() failed: %s\n", FormatError(curlm_domain,
"curl_multi_fdset() failed: %s",
curl_multi_strerror(mcode)); curl_multi_strerror(mcode));
return; return;
} }
...@@ -537,7 +536,8 @@ CurlSockets::PrepareSockets() ...@@ -537,7 +536,8 @@ CurlSockets::PrepareSockets()
return timeout2; return timeout2;
} else { } else {
g_warning("curl_multi_timeout() failed: %s\n", FormatWarning(curlm_domain,
"curl_multi_timeout() failed: %s",
curl_multi_strerror(mcode)); curl_multi_strerror(mcode));
return -1; return -1;
} }
...@@ -880,7 +880,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream) ...@@ -880,7 +880,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
buffer[end - value] = 0; buffer[end - value] = 0;
icy_metaint = g_ascii_strtoull(buffer, NULL, 10); icy_metaint = g_ascii_strtoull(buffer, NULL, 10);
g_debug("icy-metaint=%zu", icy_metaint); FormatDebug(curl_domain, "icy-metaint=%zu", icy_metaint);
if (icy_metaint > 0) { if (icy_metaint > 0) {
c->icy.Start(icy_metaint); c->icy.Start(icy_metaint);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "InputStream.hxx" #include "InputStream.hxx"
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "Log.hxx"
extern "C" { extern "C" {
#include <despotify.h> #include <despotify.h>
...@@ -85,7 +86,7 @@ refill_buffer(DespotifyInputStream *ctx) ...@@ -85,7 +86,7 @@ refill_buffer(DespotifyInputStream *ctx)
break; break;
if (rc < 0) { if (rc < 0) {
g_debug("despotify_get_pcm error\n"); LogDebug(despotify_domain, "despotify_get_pcm error");
ctx->eof = true; ctx->eof = true;
break; break;
} }
...@@ -108,14 +109,14 @@ static void callback(gcc_unused struct despotify_session* ds, ...@@ -108,14 +109,14 @@ static void callback(gcc_unused struct despotify_session* ds,
break; break;
case DESPOTIFY_TRACK_PLAY_ERROR: case DESPOTIFY_TRACK_PLAY_ERROR:
g_debug("Track play error\n"); LogWarning(despotify_domain, "Track play error");
ctx->eof = true; ctx->eof = true;
ctx->len_available = 0; ctx->len_available = 0;
break; break;
case DESPOTIFY_END_OF_PLAYLIST: case DESPOTIFY_END_OF_PLAYLIST:
ctx->eof = true; ctx->eof = true;
g_debug("End of playlist: %d\n", ctx->eof); FormatDebug(despotify_domain, "End of playlist: %d", ctx->eof);
break; break;
} }
} }
...@@ -139,7 +140,7 @@ input_despotify_open(const char *url, ...@@ -139,7 +140,7 @@ input_despotify_open(const char *url,
ds_link = despotify_link_from_uri(url + 6); ds_link = despotify_link_from_uri(url + 6);
if (!ds_link) { if (!ds_link) {
g_debug("Can't find %s\n", url); FormatDebug(despotify_domain, "Can't find %s", url);
return NULL; return NULL;
} }
if (ds_link->type != LINK_TYPE_TRACK) { if (ds_link->type != LINK_TYPE_TRACK) {
......
...@@ -34,9 +34,6 @@ extern "C" { ...@@ -34,9 +34,6 @@ extern "C" {
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
} }
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_ffmpeg"
struct FfmpegInputStream { struct FfmpegInputStream {
struct input_stream base; struct input_stream base;
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_file"
static constexpr Domain file_domain("file"); static constexpr Domain file_domain("file");
struct FileInputStream { struct FileInputStream {
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_mms"
struct MmsInputStream { struct MmsInputStream {
struct input_stream base; struct input_stream base;
......
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_rewind"
extern const struct input_plugin rewind_input_plugin; extern const struct input_plugin rewind_input_plugin;
struct RewindInputStream { struct RewindInputStream {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "util/ReusableArray.hxx" #include "util/ReusableArray.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <algorithm> #include <algorithm>
...@@ -124,7 +125,8 @@ AlsaMixerMonitor::DispatchSockets() ...@@ -124,7 +125,8 @@ AlsaMixerMonitor::DispatchSockets()
int err = snd_mixer_handle_events(mixer); int err = snd_mixer_handle_events(mixer);
if (err < 0) { if (err < 0) {
g_warning("snd_mixer_handle_events() failed: %s", FormatError(alsa_mixer_domain,
"snd_mixer_handle_events() failed: %s",
snd_strerror(err)); snd_strerror(err));
if (err == -ENODEV) { if (err == -ENODEV) {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "system/fd_util.h" #include "system/fd_util.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -190,7 +191,8 @@ OssMixer::GetVolume(Error &error) ...@@ -190,7 +191,8 @@ OssMixer::GetVolume(Error &error)
right = (level & 0xff00) >> 8; right = (level & 0xff00) >> 8;
if (left != right) { if (left != right) {
g_warning("volume for left and right is not the same, \"%i\" and " FormatWarning(oss_mixer_domain,
"volume for left and right is not the same, \"%i\" and "
"\"%i\"\n", left, right); "\"%i\"\n", left, right);
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -37,9 +38,6 @@ ...@@ -37,9 +38,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pulse_mixer"
struct PulseMixer final : public Mixer { struct PulseMixer final : public Mixer {
PulseOutput *output; PulseOutput *output;
...@@ -104,7 +102,8 @@ pulse_mixer_update(PulseMixer *pm, ...@@ -104,7 +102,8 @@ pulse_mixer_update(PulseMixer *pm,
pa_stream_get_index(stream), pa_stream_get_index(stream),
pulse_mixer_volume_cb, pm); pulse_mixer_volume_cb, pm);
if (o == NULL) { if (o == NULL) {
g_warning("pa_context_get_sink_input_info() failed: %s", FormatError(pulse_mixer_domain,
"pa_context_get_sink_input_info() failed: %s",
pa_strerror(pa_context_errno(context))); pa_strerror(pa_context_errno(context)));
pulse_mixer_offline(pm); pulse_mixer_offline(pm);
return; return;
...@@ -125,7 +124,8 @@ pulse_mixer_on_connect(gcc_unused PulseMixer *pm, ...@@ -125,7 +124,8 @@ pulse_mixer_on_connect(gcc_unused PulseMixer *pm,
(pa_subscription_mask_t)PA_SUBSCRIPTION_MASK_SINK_INPUT, (pa_subscription_mask_t)PA_SUBSCRIPTION_MASK_SINK_INPUT,
NULL, NULL); NULL, NULL);
if (o == NULL) { if (o == NULL) {
g_warning("pa_context_subscribe() failed: %s", FormatError(pulse_mixer_domain,
"pa_context_subscribe() failed: %s",
pa_strerror(pa_context_errno(context))); pa_strerror(pa_context_errno(context)));
return; return;
} }
......
...@@ -30,9 +30,6 @@ ...@@ -30,9 +30,6 @@
#include <math.h> #include <math.h>
#include <windows.h> #include <windows.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "winmm_mixer"
struct WinmmMixer final : public Mixer { struct WinmmMixer final : public Mixer {
WinmmOutput *output; WinmmOutput *output;
......
...@@ -25,15 +25,13 @@ ...@@ -25,15 +25,13 @@
#include "util/Manual.hxx" #include "util/Manual.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <string> #include <string>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "alsa"
#define ALSA_PCM_NEW_HW_PARAMS_API #define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API #define ALSA_PCM_NEW_SW_PARAMS_API
...@@ -216,7 +214,8 @@ alsa_test_default_device(void) ...@@ -216,7 +214,8 @@ alsa_test_default_device(void)
int ret = snd_pcm_open(&handle, default_device, int ret = snd_pcm_open(&handle, default_device,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (ret) { if (ret) {
g_message("Error opening default ALSA device: %s\n", FormatError(alsa_output_domain,
"Error opening default ALSA device: %s",
snd_strerror(-ret)); snd_strerror(-ret));
return false; return false;
} else } else
...@@ -413,9 +412,11 @@ configure_hw: ...@@ -413,9 +412,11 @@ configure_hw:
err = snd_pcm_hw_params_set_access(ad->pcm, hwparams, err = snd_pcm_hw_params_set_access(ad->pcm, hwparams,
SND_PCM_ACCESS_MMAP_INTERLEAVED); SND_PCM_ACCESS_MMAP_INTERLEAVED);
if (err < 0) { if (err < 0) {
g_warning("Cannot set mmap'ed mode on ALSA device \"%s\": %s\n", FormatWarning(alsa_output_domain,
"Cannot set mmap'ed mode on ALSA device \"%s\": %s",
alsa_device(ad), snd_strerror(-err)); alsa_device(ad), snd_strerror(-err));
g_warning("Falling back to direct write mode\n"); LogWarning(alsa_output_domain,
"Falling back to direct write mode");
ad->use_mmap = false; ad->use_mmap = false;
} else } else
ad->writei = snd_pcm_mmap_writei; ad->writei = snd_pcm_mmap_writei;
...@@ -443,7 +444,8 @@ configure_hw: ...@@ -443,7 +444,8 @@ configure_hw:
snd_pcm_format_t format; snd_pcm_format_t format;
if (snd_pcm_hw_params_get_format(hwparams, &format) == 0) if (snd_pcm_hw_params_get_format(hwparams, &format) == 0)
g_debug("format=%s (%s)", snd_pcm_format_name(format), FormatDebug(alsa_output_domain,
"format=%s (%s)", snd_pcm_format_name(format),
snd_pcm_format_description(format)); snd_pcm_format_description(format));
err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams, err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams,
...@@ -473,7 +475,7 @@ configure_hw: ...@@ -473,7 +475,7 @@ configure_hw:
unsigned buffer_time_min, buffer_time_max; unsigned buffer_time_min, buffer_time_max;
snd_pcm_hw_params_get_buffer_time_min(hwparams, &buffer_time_min, 0); snd_pcm_hw_params_get_buffer_time_min(hwparams, &buffer_time_min, 0);
snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time_max, 0); snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time_max, 0);
g_debug("buffer: size=%u..%u time=%u..%u", FormatDebug(alsa_output_domain, "buffer: size=%u..%u time=%u..%u",
(unsigned)buffer_size_min, (unsigned)buffer_size_max, (unsigned)buffer_size_min, (unsigned)buffer_size_max,
buffer_time_min, buffer_time_max); buffer_time_min, buffer_time_max);
...@@ -483,7 +485,7 @@ configure_hw: ...@@ -483,7 +485,7 @@ configure_hw:
unsigned period_time_min, period_time_max; unsigned period_time_min, period_time_max;
snd_pcm_hw_params_get_period_time_min(hwparams, &period_time_min, 0); snd_pcm_hw_params_get_period_time_min(hwparams, &period_time_min, 0);
snd_pcm_hw_params_get_period_time_max(hwparams, &period_time_max, 0); snd_pcm_hw_params_get_period_time_max(hwparams, &period_time_max, 0);
g_debug("period: size=%u..%u time=%u..%u", FormatDebug(alsa_output_domain, "period: size=%u..%u time=%u..%u",
(unsigned)period_size_min, (unsigned)period_size_max, (unsigned)period_size_min, (unsigned)period_size_max,
period_time_min, period_time_max); period_time_min, period_time_max);
...@@ -504,7 +506,8 @@ configure_hw: ...@@ -504,7 +506,8 @@ configure_hw:
if (period_time_ro == 0 && buffer_time >= 10000) { if (period_time_ro == 0 && buffer_time >= 10000) {
period_time_ro = period_time = buffer_time / 4; period_time_ro = period_time = buffer_time / 4;
g_debug("default period_time = buffer_time/4 = %u/4 = %u", FormatDebug(alsa_output_domain,
"default period_time = buffer_time/4 = %u/4 = %u",
buffer_time, period_time); buffer_time, period_time);
} }
...@@ -525,7 +528,8 @@ configure_hw: ...@@ -525,7 +528,8 @@ configure_hw:
} else if (err < 0) } else if (err < 0)
goto error; goto error;
if (retry != MPD_ALSA_RETRY_NR) if (retry != MPD_ALSA_RETRY_NR)
g_debug("ALSA period_time set to %d\n", period_time); FormatDebug(alsa_output_domain,
"ALSA period_time set to %d", period_time);
snd_pcm_uframes_t alsa_buffer_size; snd_pcm_uframes_t alsa_buffer_size;
cmd = "snd_pcm_hw_params_get_buffer_size"; cmd = "snd_pcm_hw_params_get_buffer_size";
...@@ -567,7 +571,7 @@ configure_hw: ...@@ -567,7 +571,7 @@ configure_hw:
if (err < 0) if (err < 0)
goto error; goto error;
g_debug("buffer_size=%u period_size=%u", FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u",
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size); (unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
if (alsa_period_size == 0) if (alsa_period_size == 0)
...@@ -673,7 +677,8 @@ alsa_open(struct audio_output *ao, AudioFormat &audio_format, Error &error) ...@@ -673,7 +677,8 @@ alsa_open(struct audio_output *ao, AudioFormat &audio_format, Error &error)
return false; return false;
} }
g_debug("opened %s type=%s", snd_pcm_name(ad->pcm), FormatDebug(alsa_output_domain, "opened %s type=%s",
snd_pcm_name(ad->pcm),
snd_pcm_type_name(snd_pcm_type(ad->pcm))); snd_pcm_type_name(snd_pcm_type(ad->pcm)));
if (!alsa_setup_or_dsd(ad, audio_format, error)) { if (!alsa_setup_or_dsd(ad, audio_format, error)) {
...@@ -700,9 +705,12 @@ static int ...@@ -700,9 +705,12 @@ static int
alsa_recover(AlsaOutput *ad, int err) alsa_recover(AlsaOutput *ad, int err)
{ {
if (err == -EPIPE) { if (err == -EPIPE) {
g_debug("Underrun on ALSA device \"%s\"\n", alsa_device(ad)); FormatDebug(alsa_output_domain,
"Underrun on ALSA device \"%s\"", alsa_device(ad));
} else if (err == -ESTRPIPE) { } else if (err == -ESTRPIPE) {
g_debug("ALSA device \"%s\" was suspended\n", alsa_device(ad)); FormatDebug(alsa_output_domain,
"ALSA device \"%s\" was suspended",
alsa_device(ad));
} }
switch (snd_pcm_state(ad->pcm)) { switch (snd_pcm_state(ad->pcm)) {
......
...@@ -22,15 +22,13 @@ ...@@ -22,15 +22,13 @@
#include "OutputAPI.hxx" #include "OutputAPI.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <ao/ao.h> #include <ao/ao.h>
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ao"
/* An ao_sample_format, with all fields set to zero: */ /* An ao_sample_format, with all fields set to zero: */
static ao_sample_format OUR_AO_FORMAT_INITIALIZER; static ao_sample_format OUR_AO_FORMAT_INITIALIZER;
...@@ -125,8 +123,8 @@ AoOutput::Configure(const config_param &param, Error &error) ...@@ -125,8 +123,8 @@ AoOutput::Configure(const config_param &param, Error &error)
return false; return false;
} }
g_debug("using ao driver \"%s\" for \"%s\"\n", ai->short_name, FormatDebug(ao_output_domain, "using ao driver \"%s\" for \"%s\"\n",
param.GetBlockValue("name", nullptr)); ai->short_name, param.GetBlockValue("name", nullptr));
value = param.GetBlockValue("options", nullptr); value = param.GetBlockValue("options", nullptr);
if (value != nullptr) { if (value != nullptr) {
......
...@@ -27,19 +27,15 @@ ...@@ -27,19 +27,15 @@
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include "open.h" #include "open.h"
#include <glib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "fifo"
#define FIFO_BUFFER_SIZE 65536 /* pipe capacity on Linux >= 2.6.11 */ #define FIFO_BUFFER_SIZE 65536 /* pipe capacity on Linux >= 2.6.11 */
struct FifoOutput { struct FifoOutput {
...@@ -78,11 +74,13 @@ static constexpr Domain fifo_output_domain("fifo_output"); ...@@ -78,11 +74,13 @@ static constexpr Domain fifo_output_domain("fifo_output");
inline void inline void
FifoOutput::Delete() FifoOutput::Delete()
{ {
g_debug("Removing FIFO \"%s\"", path_utf8.c_str()); FormatDebug(fifo_output_domain,
"Removing FIFO \"%s\"", path_utf8.c_str());
if (!RemoveFile(path)) { if (!RemoveFile(path)) {
g_warning("Could not remove FIFO \"%s\": %s", FormatErrno(fifo_output_domain,
path_utf8.c_str(), g_strerror(errno)); "Could not remove FIFO \"%s\"",
path_utf8.c_str());
return; return;
} }
...@@ -249,8 +247,9 @@ fifo_output_cancel(struct audio_output *ao) ...@@ -249,8 +247,9 @@ fifo_output_cancel(struct audio_output *ao)
bytes = read(fd->input, buf, FIFO_BUFFER_SIZE); bytes = read(fd->input, buf, FIFO_BUFFER_SIZE);
if (bytes < 0 && errno != EAGAIN) { if (bytes < 0 && errno != EAGAIN) {
g_warning("Flush of FIFO \"%s\" failed: %s", FormatErrno(fifo_output_domain,
fd->path_utf8.c_str(), g_strerror(errno)); "Flush of FIFO \"%s\" failed",
fd->path_utf8.c_str());
} }
} }
......
...@@ -24,13 +24,11 @@ ...@@ -24,13 +24,11 @@
#include "Page.hxx" #include "Page.hxx"
#include "IcyMetaDataServer.hxx" #include "IcyMetaDataServer.hxx"
#include "system/SocketError.hxx" #include "system/SocketError.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "httpd_output"
HttpdClient::~HttpdClient() HttpdClient::~HttpdClient()
{ {
if (state == RESPONSE) { if (state == RESPONSE) {
...@@ -80,7 +78,8 @@ HttpdClient::HandleLine(const char *line) ...@@ -80,7 +78,8 @@ HttpdClient::HandleLine(const char *line)
if (state == REQUEST) { if (state == REQUEST) {
if (strncmp(line, "GET /", 5) != 0) { if (strncmp(line, "GET /", 5) != 0) {
/* only GET is supported */ /* only GET is supported */
g_warning("malformed request line from client"); LogWarning(httpd_output_domain,
"malformed request line from client");
return false; return false;
} }
...@@ -171,7 +170,9 @@ HttpdClient::SendResponse() ...@@ -171,7 +170,9 @@ HttpdClient::SendResponse()
ssize_t nbytes = SocketMonitor::Write(buffer, strlen(buffer)); ssize_t nbytes = SocketMonitor::Write(buffer, strlen(buffer));
if (gcc_unlikely(nbytes < 0)) { if (gcc_unlikely(nbytes < 0)) {
const SocketErrorMessage msg; const SocketErrorMessage msg;
g_warning("failed to write to client: %s", (const char *)msg); FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg);
Close(); Close();
return false; return false;
} }
...@@ -278,7 +279,8 @@ HttpdClient::TryWrite() ...@@ -278,7 +279,8 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) { if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e); SocketErrorMessage msg(e);
g_warning("failed to write to client: %s", FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg); (const char *)msg);
} }
...@@ -304,7 +306,8 @@ HttpdClient::TryWrite() ...@@ -304,7 +306,8 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) { if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e); SocketErrorMessage msg(e);
g_warning("failed to write to client: %s", FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg); (const char *)msg);
} }
...@@ -326,7 +329,8 @@ HttpdClient::TryWrite() ...@@ -326,7 +329,8 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) { if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e); SocketErrorMessage msg(e);
g_warning("failed to write to client: %s", FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg); (const char *)msg);
} }
...@@ -399,7 +403,8 @@ BufferedSocket::InputResult ...@@ -399,7 +403,8 @@ BufferedSocket::InputResult
HttpdClient::OnSocketInput(const void *data, size_t length) HttpdClient::OnSocketInput(const void *data, size_t length)
{ {
if (state == RESPONSE) { if (state == RESPONSE) {
g_warning("unexpected input from client"); LogWarning(httpd_output_domain,
"unexpected input from client");
LockClose(); LockClose();
return InputResult::CLOSED; return InputResult::CLOSED;
} }
...@@ -433,7 +438,7 @@ HttpdClient::OnSocketInput(const void *data, size_t length) ...@@ -433,7 +438,7 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
void void
HttpdClient::OnSocketError(Error &&error) HttpdClient::OnSocketError(Error &&error)
{ {
g_warning("error on HTTP client: %s", error.GetMessage()); LogError(error);
} }
void void
......
...@@ -205,4 +205,6 @@ private: ...@@ -205,4 +205,6 @@ private:
size_t address_length, int uid) override; size_t address_length, int uid) override;
}; };
extern const class Domain httpd_output_domain;
#endif #endif
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "Main.hxx" #include "Main.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
...@@ -44,10 +45,7 @@ ...@@ -44,10 +45,7 @@
#include <tcpd.h> #include <tcpd.h>
#endif #endif
#undef G_LOG_DOMAIN const Domain httpd_output_domain("httpd_output");
#define G_LOG_DOMAIN "httpd_output"
static constexpr Domain httpd_output_domain("httpd_output");
inline inline
HttpdOutput::HttpdOutput(EventLoop &_loop) HttpdOutput::HttpdOutput(EventLoop &_loop)
...@@ -210,7 +208,8 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address, ...@@ -210,7 +208,8 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address,
if (!hosts_access(&req)) { if (!hosts_access(&req)) {
/* tcp wrappers says no */ /* tcp wrappers says no */
g_warning("libwrap refused connection (libwrap=%s) from %s", FormatWarning(httpd_output_domain,
"libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr); progname, hostaddr);
g_free(hostaddr); g_free(hostaddr);
close_socket(fd); close_socket(fd);
...@@ -233,7 +232,7 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address, ...@@ -233,7 +232,7 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address,
else else
close_socket(fd); close_socket(fd);
} else if (fd < 0 && errno != EINTR) { } else if (fd < 0 && errno != EINTR) {
g_warning("accept() failed: %s", g_strerror(errno)); LogErrno(httpd_output_domain, "accept() failed");
} }
} }
...@@ -420,7 +419,8 @@ HttpdOutput::BroadcastFromEncoder() ...@@ -420,7 +419,8 @@ HttpdOutput::BroadcastFromEncoder()
mutex.lock(); mutex.lock();
for (auto &client : clients) { for (auto &client : clients) {
if (client.GetQueueSize() > 256 * 1024) { if (client.GetQueueSize() > 256 * 1024) {
g_debug("client is too slow, flushing its queue"); FormatDebug(httpd_output_domain,
"client is too slow, flushing its queue");
client.CancelQueue(); client.CancelQueue();
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ConfigError.hxx" #include "ConfigError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h> #include <assert.h>
...@@ -38,9 +39,6 @@ ...@@ -38,9 +39,6 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "jack"
enum { enum {
MAX_PORTS = 16, MAX_PORTS = 16,
}; };
...@@ -216,14 +214,14 @@ set_audioformat(JackOutput *jd, AudioFormat &audio_format) ...@@ -216,14 +214,14 @@ set_audioformat(JackOutput *jd, AudioFormat &audio_format)
static void static void
mpd_jack_error(const char *msg) mpd_jack_error(const char *msg)
{ {
g_warning("%s", msg); LogError(jack_output_domain, msg);
} }
#ifdef HAVE_JACK_SET_INFO_FUNCTION #ifdef HAVE_JACK_SET_INFO_FUNCTION
static void static void
mpd_jack_info(const char *msg) mpd_jack_info(const char *msg)
{ {
g_message("%s", msg); LogInfo(jack_output_domain, msg);
} }
#endif #endif
...@@ -360,7 +358,8 @@ mpd_jack_init(const config_param &param, Error &error) ...@@ -360,7 +358,8 @@ mpd_jack_init(const config_param &param, Error &error)
/* compatibility with MPD < 0.16 */ /* compatibility with MPD < 0.16 */
value = param.GetBlockValue("ports", nullptr); value = param.GetBlockValue("ports", nullptr);
if (value != nullptr) if (value != nullptr)
g_warning("deprecated option 'ports' in line %d", FormatWarning(jack_output_domain,
"deprecated option 'ports' in line %d",
param.line); param.line);
} }
...@@ -376,7 +375,8 @@ mpd_jack_init(const config_param &param, Error &error) ...@@ -376,7 +375,8 @@ mpd_jack_init(const config_param &param, Error &error)
if (jd->num_destination_ports > 0 && if (jd->num_destination_ports > 0 &&
jd->num_destination_ports != jd->num_source_ports) jd->num_destination_ports != jd->num_source_ports)
g_warning("number of source ports (%u) mismatches the " FormatWarning(jack_output_domain,
"number of source ports (%u) mismatches the "
"number of destination ports (%u) in line %d", "number of destination ports (%u) in line %d",
jd->num_source_ports, jd->num_destination_ports, jd->num_source_ports, jd->num_destination_ports,
param.line); param.line);
...@@ -500,7 +500,8 @@ mpd_jack_start(JackOutput *jd, Error &error) ...@@ -500,7 +500,8 @@ mpd_jack_start(JackOutput *jd, Error &error)
num_destination_ports < MAX_PORTS && num_destination_ports < MAX_PORTS &&
jports[num_destination_ports] != nullptr; jports[num_destination_ports] != nullptr;
++num_destination_ports) { ++num_destination_ports) {
g_debug("destination_port[%u] = '%s'\n", FormatDebug(jack_output_domain,
"destination_port[%u] = '%s'\n",
num_destination_ports, num_destination_ports,
jports[num_destination_ports]); jports[num_destination_ports]);
destination_ports[num_destination_ports] = destination_ports[num_destination_ports] =
......
...@@ -25,15 +25,13 @@ ...@@ -25,15 +25,13 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <CoreAudio/AudioHardware.h> #include <CoreAudio/AudioHardware.h>
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "osx"
struct OSXOutput { struct OSXOutput {
struct audio_output base; struct audio_output base;
...@@ -156,13 +154,15 @@ osx_output_set_device(OSXOutput *oo, Error &error) ...@@ -156,13 +154,15 @@ osx_output_set_device(OSXOutput *oo, Error &error)
goto done; goto done;
} }
if (strcmp(oo->device_name, name) == 0) { if (strcmp(oo->device_name, name) == 0) {
g_debug("found matching device: ID=%u, name=%s", FormatDebug(osx_output_domain,
(unsigned int) deviceids[i], name); "found matching device: ID=%u, name=%s",
(unsigned)deviceids[i], name);
break; break;
} }
} }
if (i == numdevices) { if (i == numdevices) {
g_warning("Found no audio device with name '%s' " FormatWarning(osx_output_domain,
"Found no audio device with name '%s' "
"(will use default audio device)", "(will use default audio device)",
oo->device_name); oo->device_name);
goto done; goto done;
...@@ -181,8 +181,10 @@ osx_output_set_device(OSXOutput *oo, Error &error) ...@@ -181,8 +181,10 @@ osx_output_set_device(OSXOutput *oo, Error &error)
ret = false; ret = false;
goto done; goto done;
} }
g_debug("set OS X audio output device ID=%u, name=%s",
(unsigned int) deviceids[i], name); FormatDebug(osx_output_domain,
"set OS X audio output device ID=%u, name=%s",
(unsigned)deviceids[i], name);
done: done:
delete[] deviceids; delete[] deviceids;
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#include <OpenAL/alc.h> #include <OpenAL/alc.h>
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "openal"
/* should be enough for buffer size = 2048 */ /* should be enough for buffer size = 2048 */
#define NUM_BUFFERS 16 #define NUM_BUFFERS 16
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "system/fd_util.h" #include "system/fd_util.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -35,9 +36,6 @@ ...@@ -35,9 +36,6 @@
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "oss"
#if defined(__OpenBSD__) || defined(__NetBSD__) #if defined(__OpenBSD__) || defined(__NetBSD__)
# include <soundcard.h> # include <soundcard.h>
#else /* !(defined(__OpenBSD__) || defined(__NetBSD__) */ #else /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
...@@ -142,8 +140,10 @@ oss_output_test_default_device(void) ...@@ -142,8 +140,10 @@ oss_output_test_default_device(void)
close(fd); close(fd);
return true; return true;
} }
g_warning("Error opening OSS device \"%s\": %s\n",
default_devices[i], g_strerror(errno)); FormatErrno(oss_output_domain,
"Error opening OSS device \"%s\"",
default_devices[i]);
} }
return false; return false;
...@@ -177,17 +177,20 @@ oss_open_default(Error &error) ...@@ -177,17 +177,20 @@ oss_open_default(Error &error)
/* never reached */ /* never reached */
break; break;
case OSS_STAT_DOESN_T_EXIST: case OSS_STAT_DOESN_T_EXIST:
g_warning("%s not found\n", dev); FormatWarning(oss_output_domain,
"%s not found", dev);
break; break;
case OSS_STAT_NOT_CHAR_DEV: case OSS_STAT_NOT_CHAR_DEV:
g_warning("%s is not a character device\n", dev); FormatWarning(oss_output_domain,
"%s is not a character device", dev);
break; break;
case OSS_STAT_NO_PERMS: case OSS_STAT_NO_PERMS:
g_warning("%s: permission denied\n", dev); FormatWarning(oss_output_domain,
"%s: permission denied", dev);
break; break;
case OSS_STAT_OTHER: case OSS_STAT_OTHER:
g_warning("Error accessing %s: %s\n", FormatErrno(oss_output_domain, err[i],
dev, g_strerror(err[i])); "Error accessing %s", dev);
} }
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "mixer/PulseMixerPlugin.hxx" #include "mixer/PulseMixerPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -628,7 +629,8 @@ pulse_output_close(struct audio_output *ao) ...@@ -628,7 +629,8 @@ pulse_output_close(struct audio_output *ao)
o = pa_stream_drain(po->stream, o = pa_stream_drain(po->stream,
pulse_output_stream_success_cb, po); pulse_output_stream_success_cb, po);
if (o == nullptr) { if (o == nullptr) {
g_warning("pa_stream_drain() has failed: %s", FormatWarning(pulse_output_domain,
"pa_stream_drain() has failed: %s",
pa_strerror(pa_context_errno(po->context))); pa_strerror(pa_context_errno(po->context)));
} else } else
pulse_wait_for_operation(po->mainloop, o); pulse_wait_for_operation(po->mainloop, o);
...@@ -804,7 +806,8 @@ pulse_output_cancel(struct audio_output *ao) ...@@ -804,7 +806,8 @@ pulse_output_cancel(struct audio_output *ao)
o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po); o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po);
if (o == nullptr) { if (o == nullptr) {
g_warning("pa_stream_flush() has failed: %s", FormatWarning(pulse_output_domain,
"pa_stream_flush() has failed: %s",
pa_strerror(pa_context_errno(po->context))); pa_strerror(pa_context_errno(po->context)));
pa_threaded_mainloop_unlock(po->mainloop); pa_threaded_mainloop_unlock(po->mainloop);
return; return;
...@@ -829,7 +832,7 @@ pulse_output_pause(struct audio_output *ao) ...@@ -829,7 +832,7 @@ pulse_output_pause(struct audio_output *ao)
Error error; Error error;
if (!pulse_output_wait_stream(po, error)) { if (!pulse_output_wait_stream(po, error)) {
pa_threaded_mainloop_unlock(po->mainloop); pa_threaded_mainloop_unlock(po->mainloop);
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
...@@ -840,7 +843,7 @@ pulse_output_pause(struct audio_output *ao) ...@@ -840,7 +843,7 @@ pulse_output_pause(struct audio_output *ao)
if (!pa_stream_is_corked(po->stream) && if (!pa_stream_is_corked(po->stream) &&
!pulse_output_stream_pause(po, true, error)) { !pulse_output_stream_pause(po, true, error)) {
pa_threaded_mainloop_unlock(po->mainloop); pa_threaded_mainloop_unlock(po->mainloop);
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
......
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "recorder"
struct RecorderOutput { struct RecorderOutput {
struct audio_output base; struct audio_output base;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -34,9 +35,6 @@ ...@@ -34,9 +35,6 @@
#include <roaraudio.h> #include <roaraudio.h>
#undef new #undef new
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "roaraudio"
struct RoarOutput { struct RoarOutput {
struct audio_output base; struct audio_output base;
...@@ -242,7 +240,7 @@ roar_cancel_locked(RoarOutput *self) ...@@ -242,7 +240,7 @@ roar_cancel_locked(RoarOutput *self)
if (roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY, if (roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY,
&(self->err)) < 0) { &(self->err)) < 0) {
roar_vs_close(vss, ROAR_VS_TRUE, &(self->err)); roar_vs_close(vss, ROAR_VS_TRUE, &(self->err));
g_warning("Failed to start stream"); LogError(roar_output_domain, "Failed to start stream");
return; return;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <shout/shout.h> #include <shout/shout.h>
#include <glib.h> #include <glib.h>
...@@ -35,9 +36,6 @@ ...@@ -35,9 +36,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "shout"
static constexpr unsigned DEFAULT_CONN_TIMEOUT = 2; static constexpr unsigned DEFAULT_CONN_TIMEOUT = 2;
struct ShoutOutput final { struct ShoutOutput final {
...@@ -358,7 +356,8 @@ static void close_shout_conn(ShoutOutput * sd) ...@@ -358,7 +356,8 @@ static void close_shout_conn(ShoutOutput * sd)
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED && if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) { shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) {
g_warning("problem closing connection to shout server: %s\n", FormatWarning(shout_output_domain,
"problem closing connection to shout server: %s",
shout_get_error(sd->shout_conn)); shout_get_error(sd->shout_conn));
} }
} }
...@@ -507,7 +506,7 @@ static void my_shout_set_tag(struct audio_output *ao, ...@@ -507,7 +506,7 @@ static void my_shout_set_tag(struct audio_output *ao,
if (!encoder_pre_tag(sd->encoder, error) || if (!encoder_pre_tag(sd->encoder, error) ||
!write_page(sd, error) || !write_page(sd, error) ||
!encoder_tag(sd->encoder, tag, error)) { !encoder_tag(sd->encoder, tag, error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return; return;
} }
} else { } else {
...@@ -518,7 +517,8 @@ static void my_shout_set_tag(struct audio_output *ao, ...@@ -518,7 +517,8 @@ static void my_shout_set_tag(struct audio_output *ao,
shout_metadata_add(sd->shout_meta, "song", song); shout_metadata_add(sd->shout_meta, "song", song);
if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn, if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn,
sd->shout_meta)) { sd->shout_meta)) {
g_warning("error setting shout metadata\n"); LogWarning(shout_output_domain,
"error setting shout metadata");
} }
} }
......
...@@ -49,9 +49,6 @@ struct audio_info { ...@@ -49,9 +49,6 @@ struct audio_info {
#endif #endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "solaris_output"
struct SolarisOutput { struct SolarisOutput {
struct audio_output base; struct audio_output base;
......
...@@ -30,9 +30,6 @@ ...@@ -30,9 +30,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "winmm_output"
struct WinmmBuffer { struct WinmmBuffer {
PcmBuffer buffer; PcmBuffer buffer;
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
const Domain pcm_convert_domain("pcm_convert"); const Domain pcm_convert_domain("pcm_convert");
PcmConvert::PcmConvert() PcmConvert::PcmConvert()
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "PcmResampleInternal.hxx" #include "PcmResampleInternal.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -28,9 +29,6 @@ ...@@ -28,9 +29,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static int lsr_converter = SRC_SINC_FASTEST; static int lsr_converter = SRC_SINC_FASTEST;
static constexpr Domain libsamplerate_domain("libsamplerate"); static constexpr Domain libsamplerate_domain("libsamplerate");
...@@ -74,7 +72,8 @@ pcm_resample_lsr_global_init(const char *converter, Error &error) ...@@ -74,7 +72,8 @@ pcm_resample_lsr_global_init(const char *converter, Error &error)
return false; return false;
} }
g_debug("libsamplerate converter '%s'", FormatDebug(libsamplerate_domain,
"libsamplerate converter '%s'",
src_get_name(lsr_converter)); src_get_name(lsr_converter));
return true; return true;
...@@ -133,7 +132,8 @@ pcm_resample_set(PcmResampler *state, ...@@ -133,7 +132,8 @@ pcm_resample_set(PcmResampler *state,
SRC_DATA *data = &state->data; SRC_DATA *data = &state->data;
data->src_ratio = (double)dest_rate / (double)src_rate; data->src_ratio = (double)dest_rate / (double)src_rate;
g_debug("setting samplerate conversion ratio to %.2lf", FormatDebug(libsamplerate_domain,
"setting samplerate conversion ratio to %.2lf",
data->src_ratio); data->src_ratio);
src_set_ratio(state->state, data->src_ratio); src_set_ratio(state->state, data->src_ratio);
......
...@@ -27,9 +27,6 @@ ...@@ -27,9 +27,6 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm_volume"
static void static void
pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume)
{ {
......
...@@ -25,14 +25,15 @@ ...@@ -25,14 +25,15 @@
#include "Song.hxx" #include "Song.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain asx_domain("asx");
#define G_LOG_DOMAIN "asx"
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
...@@ -224,7 +225,7 @@ asx_open_stream(struct input_stream *is) ...@@ -224,7 +225,7 @@ asx_open_stream(struct input_stream *is)
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
g_warning("%s", error2.GetMessage()); LogError(error2);
return NULL; return NULL;
} }
...@@ -234,7 +235,8 @@ asx_open_stream(struct input_stream *is) ...@@ -234,7 +235,8 @@ asx_open_stream(struct input_stream *is)
success = g_markup_parse_context_parse(context, buffer, nbytes, success = g_markup_parse_context_parse(context, buffer, nbytes,
&error); &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatErrno(asx_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
...@@ -243,7 +245,8 @@ asx_open_stream(struct input_stream *is) ...@@ -243,7 +245,8 @@ asx_open_stream(struct input_stream *is)
success = g_markup_parse_context_end_parse(context, &error); success = g_markup_parse_context_end_parse(context, &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatErrno(asx_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
......
...@@ -29,9 +29,6 @@ ...@@ -29,9 +29,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "cue"
class CuePlaylist final : public SongEnumerator { class CuePlaylist final : public SongEnumerator {
struct input_stream *is; struct input_stream *is;
TextInputStream tis; TextInputStream tis;
......
...@@ -24,13 +24,12 @@ ...@@ -24,13 +24,12 @@
#include "MemorySongEnumerator.hxx" #include "MemorySongEnumerator.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Log.hxx"
extern "C" { extern "C" {
#include <despotify.h> #include <despotify.h>
} }
#include <glib.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -48,7 +47,8 @@ add_song(std::forward_list<SongPointer> &songs, struct ds_track *track) ...@@ -48,7 +47,8 @@ add_song(std::forward_list<SongPointer> &songs, struct ds_track *track)
if (despotify_track_to_uri(track, ds_uri) != ds_uri) { if (despotify_track_to_uri(track, ds_uri) != ds_uri) {
/* Should never really fail, but let's be sure */ /* Should never really fail, but let's be sure */
g_debug("Can't add track %s\n", track->title); FormatDebug(despotify_domain,
"Can't add track %s", track->title);
return; return;
} }
...@@ -99,7 +99,7 @@ despotify_playlist_open_uri(const char *url, ...@@ -99,7 +99,7 @@ despotify_playlist_open_uri(const char *url,
ds_link *link = ds_link *link =
despotify_link_from_uri(url + strlen(despotify_playlist_plugin.schemes[0]) + 3); despotify_link_from_uri(url + strlen(despotify_playlist_plugin.schemes[0]) + 3);
if (link == nullptr) { if (link == nullptr) {
g_debug("Can't find %s\n", url); FormatDebug(despotify_domain, "Can't find %s\n", url);
return nullptr; return nullptr;
} }
......
...@@ -39,9 +39,6 @@ ...@@ -39,9 +39,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "cue"
class EmbeddedCuePlaylist final : public SongEnumerator { class EmbeddedCuePlaylist final : public SongEnumerator {
public: public:
/** /**
......
...@@ -25,11 +25,15 @@ ...@@ -25,11 +25,15 @@
#include "Song.hxx" #include "Song.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <string> #include <string>
static constexpr Domain pls_domain("pls");
static void static void
pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs) pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs)
{ {
...@@ -40,7 +44,8 @@ pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs) ...@@ -40,7 +44,8 @@ pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs)
int num_entries = g_key_file_get_integer(keyfile, "playlist", int num_entries = g_key_file_get_integer(keyfile, "playlist",
"NumberOfEntries", &error); "NumberOfEntries", &error);
if (error) { if (error) {
g_debug("Invalid PLS file: '%s'", error->message); FormatError(pls_domain,
"Invalid PLS file: '%s'", error->message);
g_error_free(error); g_error_free(error);
error = NULL; error = NULL;
...@@ -59,7 +64,8 @@ pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs) ...@@ -59,7 +64,8 @@ pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs)
value = g_key_file_get_string(keyfile, "playlist", key, value = g_key_file_get_string(keyfile, "playlist", key,
&error); &error);
if(error) { if(error) {
g_debug("Invalid PLS entry %s: '%s'",key, error->message); FormatError(pls_domain, "Invalid PLS entry %s: '%s'",
key, error->message);
g_error_free(error); g_error_free(error);
g_free(key); g_free(key);
return; return;
...@@ -118,7 +124,7 @@ pls_open_stream(struct input_stream *is) ...@@ -118,7 +124,7 @@ pls_open_stream(struct input_stream *is)
nbytes = is->LockRead(buffer, sizeof(buffer), error2); nbytes = is->LockRead(buffer, sizeof(buffer), error2);
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_warning("%s", error2.GetMessage()); LogError(error2);
return NULL; return NULL;
} }
...@@ -130,7 +136,7 @@ pls_open_stream(struct input_stream *is) ...@@ -130,7 +136,7 @@ pls_open_stream(struct input_stream *is)
} while (kf_data.length() < 65536); } while (kf_data.length() < 65536);
if (kf_data.empty()) { if (kf_data.empty()) {
g_warning("KeyFile parser failed: No Data"); LogWarning(pls_domain, "KeyFile parser failed: No Data");
return NULL; return NULL;
} }
...@@ -140,7 +146,8 @@ pls_open_stream(struct input_stream *is) ...@@ -140,7 +146,8 @@ pls_open_stream(struct input_stream *is)
G_KEY_FILE_NONE, &error); G_KEY_FILE_NONE, &error);
if (!success) { if (!success) {
g_warning("KeyFile parser failed: %s", error->message); FormatError(pls_domain,
"KeyFile parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_key_file_free(keyfile); g_key_file_free(keyfile);
return NULL; return NULL;
......
...@@ -25,14 +25,15 @@ ...@@ -25,14 +25,15 @@
#include "Song.hxx" #include "Song.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain rss_domain("rss");
#define G_LOG_DOMAIN "rss"
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
...@@ -221,7 +222,7 @@ rss_open_stream(struct input_stream *is) ...@@ -221,7 +222,7 @@ rss_open_stream(struct input_stream *is)
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
g_warning("%s", error2.GetMessage()); LogError(error2);
return NULL; return NULL;
} }
...@@ -231,7 +232,8 @@ rss_open_stream(struct input_stream *is) ...@@ -231,7 +232,8 @@ rss_open_stream(struct input_stream *is)
success = g_markup_parse_context_parse(context, buffer, nbytes, success = g_markup_parse_context_parse(context, buffer, nbytes,
&error); &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatError(rss_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
...@@ -240,7 +242,8 @@ rss_open_stream(struct input_stream *is) ...@@ -240,7 +242,8 @@ rss_open_stream(struct input_stream *is)
success = g_markup_parse_context_end_parse(context, &error); success = g_markup_parse_context_end_parse(context, &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatError(rss_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "Song.hxx" #include "Song.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <yajl/yajl_parse.h> #include <yajl/yajl_parse.h>
...@@ -36,12 +38,15 @@ static struct { ...@@ -36,12 +38,15 @@ static struct {
char *apikey; char *apikey;
} soundcloud_config; } soundcloud_config;
static constexpr Domain soundcloud_domain("soundcloud");
static bool static bool
soundcloud_init(const config_param &param) soundcloud_init(const config_param &param)
{ {
soundcloud_config.apikey = param.DupBlockString("apikey"); soundcloud_config.apikey = param.DupBlockString("apikey");
if (soundcloud_config.apikey == NULL) { if (soundcloud_config.apikey == NULL) {
g_debug("disabling the soundcloud playlist plugin " LogDebug(soundcloud_domain,
"disabling the soundcloud playlist plugin "
"because API key is not set"); "because API key is not set");
return false; return false;
} }
...@@ -254,7 +259,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, ...@@ -254,7 +259,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
error); error);
if (input_stream == NULL) { if (input_stream == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
return -1; return -1;
} }
...@@ -269,7 +274,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, ...@@ -269,7 +274,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
input_stream->Read(buffer, sizeof(buffer), error); input_stream->Read(buffer, sizeof(buffer), error);
if (nbytes == 0) { if (nbytes == 0) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
if (input_stream->IsEOF()) { if (input_stream->IsEOF()) {
done = true; done = true;
...@@ -296,7 +301,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand, ...@@ -296,7 +301,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
) )
{ {
unsigned char *str = yajl_get_error(hand, 1, ubuffer, nbytes); unsigned char *str = yajl_get_error(hand, 1, ubuffer, nbytes);
g_warning("%s", str); LogError(soundcloud_domain, (const char *)str);
yajl_free_error(hand, str); yajl_free_error(hand, str);
break; break;
} }
...@@ -341,7 +346,9 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond) ...@@ -341,7 +346,9 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
rest = p; rest = p;
if (strcmp(scheme, "soundcloud") != 0) { if (strcmp(scheme, "soundcloud") != 0) {
g_warning("incompatible scheme for soundcloud plugin: %s", scheme); FormatWarning(soundcloud_domain,
"incompatible scheme for soundcloud plugin: %s",
scheme);
g_free(s); g_free(s);
return NULL; return NULL;
} }
...@@ -361,7 +368,7 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond) ...@@ -361,7 +368,7 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
g_free(s); g_free(s);
if (u == NULL) { if (u == NULL) {
g_warning("unknown soundcloud URI"); LogWarning(soundcloud_domain, "unknown soundcloud URI");
return NULL; return NULL;
} }
......
...@@ -24,14 +24,15 @@ ...@@ -24,14 +24,15 @@
#include "InputStream.hxx" #include "InputStream.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain xspf_domain("xspf");
#define G_LOG_DOMAIN "xspf"
/** /**
* This is the state object for the GLib XML parser. * This is the state object for the GLib XML parser.
...@@ -240,7 +241,7 @@ xspf_open_stream(struct input_stream *is) ...@@ -240,7 +241,7 @@ xspf_open_stream(struct input_stream *is)
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
g_warning("%s", error2.GetMessage()); LogError(error2);
return NULL; return NULL;
} }
...@@ -250,7 +251,8 @@ xspf_open_stream(struct input_stream *is) ...@@ -250,7 +251,8 @@ xspf_open_stream(struct input_stream *is)
success = g_markup_parse_context_parse(context, buffer, nbytes, success = g_markup_parse_context_parse(context, buffer, nbytes,
&error); &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatError(xspf_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
...@@ -259,7 +261,8 @@ xspf_open_stream(struct input_stream *is) ...@@ -259,7 +261,8 @@ xspf_open_stream(struct input_stream *is)
success = g_markup_parse_context_end_parse(context, &error); success = g_markup_parse_context_end_parse(context, &error);
if (!success) { if (!success) {
g_warning("XML parser failed: %s", error->message); FormatError(xspf_domain,
"XML parser failed: %s", error->message);
g_error_free(error); g_error_free(error);
g_markup_parse_context_free(context); g_markup_parse_context_free(context);
return NULL; return NULL;
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "config.h" #include "config.h"
#include "FatalError.hxx" #include "FatalError.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "LogV.hxx"
#include <glib.h> #include <glib.h>
...@@ -33,13 +35,12 @@ ...@@ -33,13 +35,12 @@
#include <errno.h> #include <errno.h>
#endif #endif
#undef G_LOG_DOMAIN static constexpr Domain fatal_error_domain("fatal_error");
#define G_LOG_DOMAIN "FatalError"
void void
FatalError(const char *msg) FatalError(const char *msg)
{ {
g_critical("%s", msg); LogError(fatal_error_domain, msg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -48,7 +49,7 @@ FormatFatalError(const char *fmt, ...) ...@@ -48,7 +49,7 @@ FormatFatalError(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, fmt, ap); LogFormatV(fatal_error_domain, LogLevel::ERROR, fmt, ap);
va_end(ap); va_end(ap);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -88,7 +89,7 @@ FatalSystemError(const char *msg) ...@@ -88,7 +89,7 @@ FatalSystemError(const char *msg)
system_error = g_strerror(errno); system_error = g_strerror(errno);
#endif #endif
g_critical("%s: %s", msg, system_error); FormatError(fatal_error_domain, "%s: %s", msg, system_error);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "Aiff.hxx" #include "Aiff.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -26,11 +28,9 @@ ...@@ -26,11 +28,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain aiff_domain("aiff");
#define G_LOG_DOMAIN "aiff"
struct aiff_header { struct aiff_header {
char id[4]; char id[4];
...@@ -50,15 +50,14 @@ aiff_seek_id3(FILE *file) ...@@ -50,15 +50,14 @@ aiff_seek_id3(FILE *file)
struct stat st; struct stat st;
if (fstat(fileno(file), &st) < 0) { if (fstat(fileno(file), &st) < 0) {
g_warning("Failed to stat file descriptor: %s", LogErrno(aiff_domain, "Failed to stat file descriptor");
g_strerror(errno));
return 0; return 0;
} }
/* seek to the beginning and read the AIFF header */ /* seek to the beginning and read the AIFF header */
if (fseek(file, 0, SEEK_SET) != 0) { if (fseek(file, 0, SEEK_SET) != 0) {
g_warning("Failed to seek: %s", g_strerror(errno)); LogErrno(aiff_domain, "Failed to seek");
return 0; return 0;
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "config.h" /* must be first for large file support */ #include "config.h" /* must be first for large file support */
#include "Riff.hxx" #include "Riff.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -26,11 +28,9 @@ ...@@ -26,11 +28,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN static constexpr Domain riff_domain("riff");
#define G_LOG_DOMAIN "riff"
struct riff_header { struct riff_header {
char id[4]; char id[4];
...@@ -50,15 +50,14 @@ riff_seek_id3(FILE *file) ...@@ -50,15 +50,14 @@ riff_seek_id3(FILE *file)
struct stat st; struct stat st;
if (fstat(fileno(file), &st) < 0) { if (fstat(fileno(file), &st) < 0) {
g_warning("Failed to stat file descriptor: %s", LogErrno(riff_domain, "Failed to stat file descriptor");
g_strerror(errno));
return 0; return 0;
} }
/* seek to the beginning and read the RIFF header */ /* seek to the beginning and read the RIFF header */
if (fseek(file, 0, SEEK_SET) != 0) { if (fseek(file, 0, SEEK_SET) != 0) {
g_warning("Failed to seek: %s", g_strerror(errno)); LogErrno(riff_domain, "Failed to seek");
return 0; return 0;
} }
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "Tag.hxx" #include "Tag.hxx"
#include "TagBuilder.hxx" #include "TagBuilder.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "Riff.hxx" #include "Riff.hxx"
#include "Aiff.hxx" #include "Aiff.hxx"
...@@ -36,9 +38,6 @@ ...@@ -36,9 +38,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "id3"
# ifndef ID3_FRAME_COMPOSER # ifndef ID3_FRAME_COMPOSER
# define ID3_FRAME_COMPOSER "TCOM" # define ID3_FRAME_COMPOSER "TCOM"
# endif # endif
...@@ -58,6 +57,8 @@ ...@@ -58,6 +57,8 @@
#define ID3_FRAME_ALBUM_ARTIST "TPE2" #define ID3_FRAME_ALBUM_ARTIST "TPE2"
#endif #endif
static constexpr Domain id3_domain("id3");
static inline bool static inline bool
tag_is_id3v1(struct id3_tag *tag) tag_is_id3v1(struct id3_tag *tag)
{ {
...@@ -104,7 +105,8 @@ import_id3_string(bool is_id3v1, const id3_ucs4_t *ucs4) ...@@ -104,7 +105,8 @@ import_id3_string(bool is_id3v1, const id3_ucs4_t *ucs4)
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr); nullptr, nullptr);
if (utf8 == nullptr) { if (utf8 == nullptr) {
g_debug("Unable to convert %s string to UTF-8: '%s'", FormatWarning(id3_domain,
"Unable to convert %s string to UTF-8: '%s'",
encoding, isostr); encoding, isostr);
g_free(isostr); g_free(isostr);
return nullptr; return nullptr;
...@@ -526,7 +528,7 @@ tag_id3_riff_aiff_load(FILE *file) ...@@ -526,7 +528,7 @@ tag_id3_riff_aiff_load(FILE *file)
id3_byte_t *buffer = (id3_byte_t *)g_malloc(size); id3_byte_t *buffer = (id3_byte_t *)g_malloc(size);
size_t ret = fread(buffer, size, 1, file); size_t ret = fread(buffer, size, 1, file);
if (ret != 1) { if (ret != 1) {
g_warning("Failed to read RIFF chunk"); LogWarning(id3_domain, "Failed to read RIFF chunk");
g_free(buffer); g_free(buffer);
return nullptr; return nullptr;
} }
...@@ -564,7 +566,7 @@ tag_id3_scan(const char *path_fs, ...@@ -564,7 +566,7 @@ tag_id3_scan(const char *path_fs,
struct id3_tag *tag = tag_id3_load(path_fs, error); struct id3_tag *tag = tag_id3_load(path_fs, error);
if (tag == nullptr) { if (tag == nullptr) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
return false; return false;
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "PlaylistPlugin.hxx" #include "PlaylistPlugin.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -174,7 +175,7 @@ int main(int argc, char **argv) ...@@ -174,7 +175,7 @@ int main(int argc, char **argv)
io_thread_start(); io_thread_start();
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
...@@ -193,7 +194,7 @@ int main(int argc, char **argv) ...@@ -193,7 +194,7 @@ int main(int argc, char **argv)
is = input_stream::Open(uri, mutex, cond, error); is = input_stream::Open(uri, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
else else
g_printerr("input_stream::Open() failed\n"); g_printerr("input_stream::Open() failed\n");
return 2; return 2;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "stdbin.h" #include "stdbin.h"
#include "TextInputStream.hxx" #include "TextInputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
#include "ArchiveList.hxx" #include "ArchiveList.hxx"
...@@ -66,7 +67,7 @@ dump_input_stream(struct input_stream *is) ...@@ -66,7 +67,7 @@ dump_input_stream(struct input_stream *is)
is->WaitReady(); is->WaitReady();
if (!is->Check(error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
is->Unlock(); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -82,7 +83,7 @@ dump_input_stream(struct input_stream *is) ...@@ -82,7 +83,7 @@ dump_input_stream(struct input_stream *is)
is->Lock(); is->Lock();
if (!is->Check(error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
is->Unlock(); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -123,7 +124,7 @@ int main(int argc, char **argv) ...@@ -123,7 +124,7 @@ int main(int argc, char **argv)
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
...@@ -138,7 +139,7 @@ int main(int argc, char **argv) ...@@ -138,7 +139,7 @@ int main(int argc, char **argv)
is->Close(); is->Close();
} else { } else {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
else else
g_printerr("input_stream::Open() failed\n"); g_printerr("input_stream::Open() failed\n");
ret = 2; ret = 2;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "tag/TagId3.hxx" #include "tag/TagId3.hxx"
#include "tag/ApeTag.hxx" #include "tag/ApeTag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -167,7 +168,7 @@ int main(int argc, char **argv) ...@@ -167,7 +168,7 @@ int main(int argc, char **argv)
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "InputStream.hxx" #include "InputStream.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include "stdbin.h" #include "stdbin.h"
#include <glib.h> #include <glib.h>
...@@ -167,7 +168,7 @@ int main(int argc, char **argv) ...@@ -167,7 +168,7 @@ int main(int argc, char **argv)
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
...@@ -192,7 +193,7 @@ int main(int argc, char **argv) ...@@ -192,7 +193,7 @@ int main(int argc, char **argv)
input_stream::Open(decoder.uri, mutex, cond, error); input_stream::Open(decoder.uri, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
else else
g_printerr("input_stream::Open() failed\n"); g_printerr("input_stream::Open() failed\n");
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "InotifySource.hxx" #include "InotifySource.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -68,14 +69,14 @@ int main(int argc, char **argv) ...@@ -68,14 +69,14 @@ int main(int argc, char **argv)
my_inotify_callback, my_inotify_callback,
nullptr, error); nullptr, error);
if (source == NULL) { if (source == NULL) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
int descriptor = source->Add(path, IN_MASK, error); int descriptor = source->Add(path, IN_MASK, error);
if (descriptor < 0) { if (descriptor < 0) {
delete source; delete source;
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "InputInit.hxx" #include "InputInit.hxx"
#include "IOThread.hxx" #include "IOThread.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
#include "ArchiveList.hxx" #include "ArchiveList.hxx"
...@@ -61,7 +62,7 @@ dump_input_stream(struct input_stream *is) ...@@ -61,7 +62,7 @@ dump_input_stream(struct input_stream *is)
is->WaitReady(); is->WaitReady();
if (!is->Check(error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
is->Unlock(); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -84,7 +85,7 @@ dump_input_stream(struct input_stream *is) ...@@ -84,7 +85,7 @@ dump_input_stream(struct input_stream *is)
num_read = is->Read(buffer, sizeof(buffer), error); num_read = is->Read(buffer, sizeof(buffer), error);
if (num_read == 0) { if (num_read == 0) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
break; break;
} }
...@@ -95,7 +96,7 @@ dump_input_stream(struct input_stream *is) ...@@ -95,7 +96,7 @@ dump_input_stream(struct input_stream *is)
} }
if (!is->Check(error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
is->Unlock(); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -136,7 +137,7 @@ int main(int argc, char **argv) ...@@ -136,7 +137,7 @@ int main(int argc, char **argv)
#endif #endif
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage()); LogError(error);
return 2; return 2;
} }
...@@ -151,7 +152,7 @@ int main(int argc, char **argv) ...@@ -151,7 +152,7 @@ int main(int argc, char **argv)
is->Close(); is->Close();
} else { } else {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); LogError(error);
else else
g_printerr("input_stream::Open() failed\n"); g_printerr("input_stream::Open() failed\n");
ret = 2; ret = 2;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "system/Resolver.hxx" #include "system/Resolver.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h> #include <glib.h>
...@@ -45,7 +46,7 @@ int main(int argc, char **argv) ...@@ -45,7 +46,7 @@ int main(int argc, char **argv)
resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM, resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM,
error); error);
if (ai == NULL) { if (ai == NULL) {
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -54,7 +55,7 @@ int main(int argc, char **argv) ...@@ -54,7 +55,7 @@ int main(int argc, char **argv)
error); error);
if (p == NULL) { if (p == NULL) {
freeaddrinfo(ai); freeaddrinfo(ai);
g_warning("%s", error.GetMessage()); LogError(error);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment