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,9 +80,9 @@ client_new(EventLoop &loop, Partition &partition, ...@@ -82,9 +80,9 @@ 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);
g_free(hostaddr); g_free(hostaddr);
close_socket(fd); close_socket(fd);
...@@ -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,23 +73,26 @@ client_process_line(Client *client, char *line) ...@@ -73,23 +73,26 @@ 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,
client->num, line); "[%u] command \"%s\" during idle",
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,
client->num); "[%u] process command list",
client->num);
auto &&cmd_list = client->cmd_list.Commit(); auto &&cmd_list = client->cmd_list.Commit();
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,
"list returned %i", client->num, ret); "[%u] process command "
"list returned %i", client->num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired()) client->IsExpired())
...@@ -101,10 +104,11 @@ client_process_line(Client *client, char *line) ...@@ -101,10 +104,11 @@ 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,
"is larger than the max (%lu)", "[%u] command list size "
client->num, "is larger than the max (%lu)",
(unsigned long)client_max_command_list_size); client->num,
(unsigned long)client_max_command_list_size);
return COMMAND_RETURN_CLOSE; return COMMAND_RETURN_CLOSE;
} }
...@@ -118,11 +122,13 @@ client_process_line(Client *client, char *line) ...@@ -118,11 +122,13 @@ 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,
client->num, line); "[%u] process command \"%s\"",
client->num, line);
ret = command_process(client, 0, line); ret = command_process(client, 0, line);
g_debug("[%u] command returned %i", FormatDebug(client_domain,
client->num, ret); "[%u] command returned %i",
client->num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired()) client->IsExpired())
......
...@@ -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,8 +61,9 @@ Check(const config_param *param) ...@@ -64,8 +61,9 @@ 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,
i.name.c_str(), i.line); "option '%s' on line %i was not recognized",
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,
mixramp_overlap - mixramp_delay); "will overlap %d chunks, %fs", chunks,
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,14 +64,14 @@ decoder_initialized(struct decoder *decoder, ...@@ -67,14 +64,14 @@ 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,8 +118,9 @@ remove_watch_directory(WatchDirectory *directory) ...@@ -120,8 +118,9 @@ 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,
"cannot continue to watch it"); "music directory was removed - "
"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,15 +160,18 @@ glue_db_init_and_load(void) ...@@ -161,15 +160,18 @@ 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,
"music_directory - disabling database"); "Found database setting without "
"music_directory - disabling database");
if (path != nullptr) if (path != nullptr)
g_message("Found db_file setting without " LogInfo(main_domain,
"music_directory - disabling database"); "Found db_file setting without "
"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,8 +527,9 @@ int mpd_main(int argc, char *argv[]) ...@@ -524,8 +527,9 @@ int mpd_main(int argc, char *argv[])
start = clock(); start = clock();
DatabaseGlobalDeinit(); DatabaseGlobalDeinit();
g_debug("db_finish took %f seconds", FormatDebug(main_domain,
((float)(clock()-start))/CLOCKS_PER_SEC); "db_finish took %f seconds",
((float)(clock()-start))/CLOCKS_PER_SEC);
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
sticker_global_finish(); sticker_global_finish();
......
...@@ -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,
path_utf8); "No permission to traverse (\"execute\") directory: %s",
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,14 +50,15 @@ ...@@ -54,14 +50,15 @@
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,
plugin->name); "Attempting to detect a %s audio device",
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,14 +304,16 @@ audio_output_new(const config_param &param, ...@@ -304,14 +304,16 @@ 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,
plugin->name); "Successfully detected a %s audio device",
plugin->name);
} }
struct audio_output *ao = ao_plugin_init(plugin, param, error); struct audio_output *ao = ao_plugin_init(plugin, param, error);
......
...@@ -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,15 +188,15 @@ ao_open(struct audio_output *ao) ...@@ -190,15 +188,15 @@ 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));
} }
static void static void
...@@ -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,8 +390,9 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk, ...@@ -390,8 +390,9 @@ 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,
sample_format_to_string(ao->in_audio_format.format)); "Cannot cross-fade format %s",
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,8 +462,9 @@ Player::CheckDecoderStartup() ...@@ -461,8 +462,9 @@ 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,
"while playing \"%s\"", uri); "problems opening audio device "
"while playing \"%s\"", uri);
g_free(uri); g_free(uri);
return true; return true;
...@@ -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,8 +113,9 @@ playlist_state_load(TextFile &file, struct playlist *playlist) ...@@ -111,8 +113,9 @@ 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,
"' not found in state file"); "'" PLAYLIST_STATE_FILE_PLAYLIST_END
"' 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,8 +72,8 @@ update_archive_tree(Directory *directory, const char *name) ...@@ -69,8 +72,8 @@ 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,8 +43,9 @@ update_song_file2(Directory *directory, ...@@ -43,8 +43,9 @@ 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,
directory->GetPath(), name); "no read permissions on %s/%s",
directory->GetPath(), name);
if (song != NULL) { if (song != NULL) {
db_lock(); db_lock();
delete_song(directory, song); delete_song(directory, song);
...@@ -67,11 +68,13 @@ update_song_file2(Directory *directory, ...@@ -67,11 +68,13 @@ 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,
directory->GetPath(), name); "ignoring unrecognized file %s/%s",
directory->GetPath(), name);
return; return;
} }
...@@ -80,14 +83,15 @@ update_song_file2(Directory *directory, ...@@ -80,14 +83,15 @@ 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,
directory->GetPath(), name); "deleting unrecognized file %s/%s",
directory->GetPath(), name);
db_lock(); db_lock();
delete_song(directory, song); delete_song(directory, song);
db_unlock(); db_unlock();
......
...@@ -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,13 +59,15 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -58,13 +59,15 @@ 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,
avahiName); "Service '%s' successfully established.",
avahiName);
break; break;
case AVAHI_ENTRY_GROUP_COLLISION: case AVAHI_ENTRY_GROUP_COLLISION:
...@@ -73,43 +76,48 @@ static void avahiGroupCallback(AvahiEntryGroup * g, ...@@ -73,43 +76,48 @@ 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,
avahiName); "Service name collision, renaming service to '%s'",
avahiName);
/* And recreate the services */ /* And recreate the services */
avahiRegisterService(avahi_entry_group_get_client(g)); avahiRegisterService(avahi_entry_group_get_client(g));
break; break;
case AVAHI_ENTRY_GROUP_FAILURE: case AVAHI_ENTRY_GROUP_FAILURE:
g_warning("Entry group failure: %s", FormatError(avahi_domain,
avahi_strerror(avahi_client_errno "Entry group failure: %s",
(avahi_entry_group_get_client(g)))); avahi_strerror(avahi_client_errno
(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 */
avahiRunning = 0; avahiRunning = 0;
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,
avahi_strerror(avahi_client_errno(c))); "Failed to create avahi EntryGroup: %s",
avahi_strerror(avahi_client_errno(c)));
goto fail; goto fail;
} }
} }
...@@ -124,16 +132,16 @@ static void avahiRegisterService(AvahiClient * c) ...@@ -124,16 +132,16 @@ 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;
} }
return; return;
...@@ -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,
avahi_strerror(reason)); "Could not reconnect: %s",
avahi_strerror(reason));
avahiRunning = 0; avahiRunning = 0;
} }
} else { } else {
g_warning("Client failure: %s (terminal)", FormatWarning(avahi_domain,
avahi_strerror(reason)); "Client failure: %s (terminal)",
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,12 +256,13 @@ AvahiInit(EventLoop &loop, const char *serviceName) ...@@ -241,12 +256,13 @@ 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,8 +143,9 @@ audiofile_setup_sample_format(AFfilehandle af_fp) ...@@ -143,8 +143,9 @@ 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,
bits); "input file has %d bit samples, converting to 16",
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,8 +233,9 @@ audiofile_scan_file(const char *file, ...@@ -232,8 +233,9 @@ 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,
file); "Failed to get total song time from: %s",
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,21 +420,24 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -424,21 +420,24 @@ 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,
NeAACDecGetErrorMessage(frame_info.error)); "error decoding AAC stream: %s",
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,
audio_format.channels, frame_info.channels); "channel count changed from %u to %u",
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,
audio_format.sample_rate, "sample rate changed from %u to %lu",
(unsigned long)frame_info.samplerate); audio_format.sample_rate,
(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,11 +331,13 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) ...@@ -328,11 +331,13 @@ 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,
name, sample_fmt); "Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt);
else else
g_warning("Unsupported libavcodec SampleFormat value: %d", FormatError(ffmpeg_domain,
sample_fmt); "Unsupported libavcodec SampleFormat value: %d",
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,8 +92,9 @@ flac_scan_file(const char *file, ...@@ -90,8 +92,9 @@ 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,
chain.GetStatusString()); "Failed to read FLAC tags: %s",
chain.GetStatusString());
return false; return false;
} }
...@@ -105,8 +108,9 @@ flac_scan_stream(struct input_stream *is, ...@@ -105,8 +108,9 @@ 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,
chain.GetStatusString()); "Failed to read FLAC tags: %s",
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,8 +306,9 @@ oggflac_scan_file(const char *file, ...@@ -299,8 +306,9 @@ 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,
chain.GetStatusString()); "Failed to read OggFLAC tags: %s",
chain.GetStatusString());
return false; return false;
} }
...@@ -314,8 +322,9 @@ oggflac_scan_stream(struct input_stream *is, ...@@ -314,8 +322,9 @@ 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,
chain.GetStatusString()); "Failed to read OggFLAC tags: %s",
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
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