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 = \
src/FilterPlugin.cxx src/FilterPlugin.hxx \
src/FilterInternal.hxx \
src/FilterRegistry.cxx src/FilterRegistry.hxx \
src/UpdateDomain.cxx src/UpdateDomain.hxx \
src/UpdateGlue.cxx src/UpdateGlue.hxx \
src/UpdateQueue.cxx src/UpdateQueue.hxx \
src/UpdateIO.cxx src/UpdateIO.hxx \
......@@ -154,7 +155,8 @@ src_mpd_SOURCES = \
src/ClientSubscribe.cxx src/ClientSubscribe.hxx \
src/ClientFile.cxx src/ClientFile.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/IOThread.cxx src/IOThread.hxx \
src/Main.cxx src/Main.hxx \
......@@ -233,6 +235,7 @@ endif
if ENABLE_INOTIFY
src_mpd_SOURCES += \
src/InotifyDomain.cxx src/InotifyDomain.hxx \
src/InotifySource.cxx src/InotifySource.hxx \
src/InotifyQueue.cxx src/InotifyQueue.hxx \
src/InotifyUpdate.cxx src/InotifyUpdate.hxx
......@@ -523,6 +526,7 @@ libdecoder_plugins_a_SOURCES += \
src/decoder/OggUtil.hxx \
src/decoder/OggSyncState.hxx \
src/decoder/OggFind.cxx src/decoder/OggFind.hxx \
src/decoder/OpusDomain.cxx src/decoder/OpusDomain.hxx \
src/decoder/OpusReader.hxx \
src/decoder/OpusHead.hxx \
src/decoder/OpusHead.cxx \
......@@ -557,6 +561,7 @@ endif
if ENABLE_VORBIS_DECODER
libdecoder_plugins_a_SOURCES += \
src/decoder/VorbisDomain.cxx src/decoder/VorbisDomain.hxx \
src/decoder/VorbisComments.cxx src/decoder/VorbisComments.hxx \
src/decoder/VorbisDecoderPlugin.cxx src/decoder/VorbisDecoderPlugin.h
endif
......@@ -567,6 +572,7 @@ libdecoder_plugins_a_SOURCES += \
src/decoder/FlacIOHandle.cxx src/decoder/FlacIOHandle.hxx \
src/decoder/FlacMetadata.cxx src/decoder/FlacMetadata.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/FlacDecoderPlugin.cxx \
src/decoder/FlacDecoderPlugin.h
......@@ -1062,13 +1068,17 @@ test_read_conf_LDADD = \
libsystem.a \
libfs.a \
$(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 = \
libsystem.a \
libutil.a \
$(GLIB_LIBS)
test_run_resolver_SOURCES = test/run_resolver.cxx
test_run_resolver_SOURCES = \
src/Log.cxx \
test/run_resolver.cxx
test_DumpDatabase_LDADD = \
$(DB_LIBS) \
......@@ -1079,6 +1089,7 @@ test_DumpDatabase_LDADD = \
libfs.a \
$(GLIB_LIBS)
test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
src/Log.cxx \
src/DatabaseError.cxx \
src/DatabaseRegistry.cxx \
src/DatabaseSelection.cxx \
......@@ -1102,6 +1113,7 @@ test_run_input_LDADD = \
$(GLIB_LIBS)
test_run_input_SOURCES = test/run_input.cxx \
test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \
src/TagSave.cxx
......@@ -1118,6 +1130,7 @@ test_visit_archive_LDADD = \
libfs.a \
$(GLIB_LIBS)
test_visit_archive_SOURCES = test/visit_archive.cxx \
src/Log.cxx \
src/IOThread.cxx \
src/InputStream.cxx
......@@ -1139,6 +1152,7 @@ test_dump_text_file_LDADD = \
$(GLIB_LIBS)
test_dump_text_file_SOURCES = test/dump_text_file.cxx \
test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \
src/TextInputStream.cxx
......@@ -1158,6 +1172,7 @@ test_dump_playlist_LDADD = \
$(GLIB_LIBS)
test_dump_playlist_SOURCES = test/dump_playlist.cxx \
$(DECODER_SRC) \
src/Log.cxx \
src/IOThread.cxx \
src/Song.cxx src/TagSave.cxx \
src/TagFile.cxx \
......@@ -1185,6 +1200,7 @@ test_run_decoder_LDADD = \
$(GLIB_LIBS)
test_run_decoder_SOURCES = test/run_decoder.cxx \
test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \
src/ReplayGainInfo.cxx \
src/AudioFormat.cxx src/CheckAudioFormat.cxx \
......@@ -1206,6 +1222,7 @@ test_read_tags_LDADD = \
libutil.a \
$(GLIB_LIBS)
test_read_tags_SOURCES = test/read_tags.cxx \
src/Log.cxx \
src/IOThread.cxx \
src/ReplayGainInfo.cxx \
src/CheckAudioFormat.cxx \
......@@ -1216,7 +1233,9 @@ test_dump_rva2_LDADD = \
$(TAG_LIBS) \
libutil.a \
$(GLIB_LIBS)
test_dump_rva2_SOURCES = test/dump_rva2.cxx
test_dump_rva2_SOURCES = \
src/Log.cxx \
test/dump_rva2.cxx
endif
test_run_filter_LDADD = \
......@@ -1229,6 +1248,7 @@ test_run_filter_LDADD = \
test_run_filter_SOURCES = test/run_filter.cxx \
test/FakeReplayGainConfig.cxx \
test/stdbin.h \
src/Log.cxx \
src/FilterPlugin.cxx src/FilterRegistry.cxx \
src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \
......@@ -1248,6 +1268,7 @@ if ENABLE_ENCODER
noinst_PROGRAMS += test/run_encoder
test_run_encoder_SOURCES = test/run_encoder.cxx \
test/stdbin.h \
src/Log.cxx \
src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \
src/AudioParser.cxx
......@@ -1266,6 +1287,7 @@ if ENABLE_VORBIS_ENCODER
noinst_PROGRAMS += test/test_vorbis_encoder
test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.cxx \
test/stdbin.h \
src/Log.cxx \
src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \
src/AudioParser.cxx \
......@@ -1302,6 +1324,7 @@ test_run_normalize_LDADD = \
$(GLIB_LIBS)
test_run_convert_SOURCES = test/run_convert.cxx \
src/Log.cxx \
src/AudioFormat.cxx \
src/CheckAudioFormat.cxx \
src/AudioParser.cxx
......@@ -1326,6 +1349,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
test_run_output_SOURCES = test/run_output.cxx \
test/FakeReplayGainConfig.cxx \
test/stdbin.h \
src/Log.cxx \
src/IOThread.cxx \
src/CheckAudioFormat.cxx \
src/AudioFormat.cxx \
......@@ -1353,6 +1377,7 @@ test_read_mixer_LDADD = \
libfs.a \
$(GLIB_LIBS)
test_read_mixer_SOURCES = test/read_mixer.cxx \
src/Log.cxx \
src/MixerControl.cxx \
src/FilterPlugin.cxx \
src/filter/VolumeFilterPlugin.cxx
......@@ -1372,6 +1397,8 @@ endif
if ENABLE_INOTIFY
noinst_PROGRAMS += test/run_inotify
test_run_inotify_SOURCES = test/run_inotify.cxx \
src/Log.cxx \
src/InotifyDomain.cxx \
src/InotifySource.cxx
test_run_inotify_LDADD = \
libevent.a \
......
......@@ -61,7 +61,7 @@
foo(const char *abc, int xyz)
{
if (abc == NULL) {
g_warning("Foo happened!\n");
LogWarning("Foo happened!");
return -1;
}
......
......@@ -19,15 +19,17 @@
#include "config.h" /* must be first for large file support */
#include "ArchiveLookup.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.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
//try to stat if its real directory
if (stat(pathdupe, &st_info) == -1) {
if (errno != ENOTDIR) {
g_warning("stat %s failed (errno=%d)\n", pathdupe, errno);
FormatErrno(archive_domain,
"Failed to stat %s", pathdupe);
break;
}
} else {
......@@ -92,7 +95,9 @@ bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix
}
break;
} else {
g_warning("not a regular file %s\n", pathdupe);
FormatError(archive_domain,
"Not a regular file: %s",
pathdupe);
break;
}
}
......
......@@ -19,6 +19,9 @@
#include "config.h"
#include "ClientInternal.hxx"
#include "util/Domain.hxx"
const Domain client_domain("client");
int client_get_uid(const Client *client)
{
......
......@@ -20,13 +20,12 @@
#include "config.h"
#include "ClientInternal.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include "Log.hxx"
void
Client::OnSocketError(Error &&error)
{
g_warning("error on client %d: %s", num, error.GetMessage());
FormatError(error, "error on client %d", num);
SetExpired();
}
......
......@@ -19,6 +19,7 @@
#include "config.h"
#include "ClientInternal.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -37,7 +38,7 @@ Client::OnTimeout()
{
if (!IsExpired()) {
assert(!idle_waiting);
g_debug("[%u] timeout", num);
FormatDebug(client_domain, "[%u] timeout", num);
}
Close();
......
......@@ -32,9 +32,6 @@
#include <string>
#include <list>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "client"
enum {
CLIENT_MAX_SUBSCRIPTIONS = 16,
CLIENT_MAX_MESSAGES = 64,
......@@ -123,6 +120,8 @@ private:
virtual void OnTimeout() override;
};
extern const class Domain client_domain;
extern int client_timeout;
extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;
......
......@@ -26,6 +26,7 @@
#include "system/Resolver.hxx"
#include "Permission.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <assert.h>
#include <sys/types.h>
......@@ -40,9 +41,6 @@
#include <tcpd.h>
#endif
#define LOG_LEVEL_SECURE G_LOG_LEVEL_INFO
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
Client::Client(EventLoop &_loop, Partition &_partition,
......@@ -82,9 +80,9 @@ client_new(EventLoop &loop, Partition &partition,
if (!hosts_access(&req)) {
/* tcp wrappers says no */
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
"libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr);
FormatWarning(client_domain,
"libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr);
g_free(hostaddr);
close_socket(fd);
......@@ -97,7 +95,7 @@ client_new(EventLoop &loop, Partition &partition,
ClientList &client_list = *partition.instance.client_list;
if (client_list.IsFull()) {
g_warning("Max Connections Reached!");
LogWarning(client_domain, "Max connections reached");
close_socket(fd);
return;
}
......@@ -110,8 +108,7 @@ client_new(EventLoop &loop, Partition &partition,
client_list.Add(*client);
remote = sockaddr_to_string(sa, sa_length, IgnoreError());
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
"[%u] opened from %s", client->num, remote);
FormatInfo(client_domain, "[%u] opened from %s", client->num, remote);
g_free(remote);
}
......@@ -122,6 +119,6 @@ Client::Close()
SetExpired();
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, "[%u] closed", num);
FormatInfo(client_domain, "[%u] closed", num);
delete this;
}
......@@ -21,6 +21,7 @@
#include "ClientInternal.hxx"
#include "protocol/Result.hxx"
#include "AllCommands.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -40,10 +41,9 @@ client_process_command_list(Client *client, bool list_ok,
for (auto &&i : list) {
char *cmd = &*i.begin();
g_debug("command_process_list: process command \"%s\"",
cmd);
FormatDebug(client_domain, "process command \"%s\"", 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())
break;
else if (list_ok)
......@@ -73,23 +73,26 @@ client_process_line(Client *client, char *line)
} else if (client->idle_waiting) {
/* during idle mode, clients must not send anything
except "noidle" */
g_warning("[%u] command \"%s\" during idle",
client->num, line);
FormatWarning(client_domain,
"[%u] command \"%s\" during idle",
client->num, line);
return COMMAND_RETURN_CLOSE;
}
if (client->cmd_list.IsActive()) {
if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
g_debug("[%u] process command list",
client->num);
FormatDebug(client_domain,
"[%u] process command list",
client->num);
auto &&cmd_list = client->cmd_list.Commit();
ret = client_process_command_list(client,
client->cmd_list.IsOKMode(),
std::move(cmd_list));
g_debug("[%u] process command "
"list returned %i", client->num, ret);
FormatDebug(client_domain,
"[%u] process command "
"list returned %i", client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired())
......@@ -101,10 +104,11 @@ client_process_line(Client *client, char *line)
client->cmd_list.Reset();
} else {
if (!client->cmd_list.Add(line)) {
g_warning("[%u] command list size "
"is larger than the max (%lu)",
client->num,
(unsigned long)client_max_command_list_size);
FormatWarning(client_domain,
"[%u] command list size "
"is larger than the max (%lu)",
client->num,
(unsigned long)client_max_command_list_size);
return COMMAND_RETURN_CLOSE;
}
......@@ -118,11 +122,13 @@ client_process_line(Client *client, char *line)
client->cmd_list.Begin(true);
ret = COMMAND_RETURN_OK;
} else {
g_debug("[%u] process command \"%s\"",
client->num, line);
FormatDebug(client_domain,
"[%u] process command \"%s\"",
client->num, line);
ret = command_process(client, 0, line);
g_debug("[%u] command returned %i",
client->num, ret);
FormatDebug(client_domain,
"[%u] command returned %i",
client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired())
......
......@@ -22,6 +22,7 @@
#include "DatabaseError.hxx"
#include "protocol/Result.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -93,7 +94,7 @@ print_error(Client *client, const Error &error)
assert(client != NULL);
assert(error.IsDefined());
g_warning("%s", error.GetMessage());
LogError(error);
if (error.IsDomain(playlist_domain)) {
return print_playlist_result(client,
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include "CommandLine.hxx"
#include "ls.hxx"
#include "LogInit.hxx"
#include "Log.hxx"
#include "ConfigGlobal.hxx"
#include "DecoderList.hxx"
......@@ -197,7 +198,8 @@ parse_cmdline(int argc, char **argv, struct options *options,
options->daemon = !option_no_daemon;
if (option_no_config) {
g_debug("Ignoring config, using daemon defaults\n");
LogDebug(cmdline_domain,
"Ignoring config, using daemon defaults");
return true;
} else if (argc <= 1) {
/* default configuration file path */
......
......@@ -28,17 +28,13 @@
#include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "config"
#define MAX_STRING_SIZE MPD_PATH_MAX+80
#define CONF_COMMENT '#'
......@@ -261,7 +257,7 @@ ReadConfigFile(ConfigData &config_data, const Path &path, Error &error)
assert(!path.IsNull());
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);
if (fp == nullptr) {
......
......@@ -23,18 +23,15 @@
#include "ConfigData.hxx"
#include "ConfigFile.hxx"
#include "ConfigPath.hxx"
#include "ConfigError.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "system/FatalError.hxx"
#include <glib.h>
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "config"
static ConfigData config_data;
void config_global_finish(void)
......@@ -64,8 +61,9 @@ Check(const config_param *param)
for (const auto &i : param->block_params) {
if (!i.used)
g_warning("option '%s' on line %i was not recognized",
i.name.c_str(), i.line);
FormatWarning(config_domain,
"option '%s' on line %i was not recognized",
i.name.c_str(), i.line);
}
}
......
......@@ -21,23 +21,25 @@
#include "CrossFade.hxx"
#include "MusicChunk.hxx"
#include "AudioFormat.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <cmath>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "crossfade"
static constexpr Domain cross_fade_domain("cross_fade");
#ifdef WIN32
#ifdef G_OS_WIN32
static char *
strtok_r(char *str, const char *delim, gcc_unused char **saveptr)
{
return strtok(str, delim);
}
#endif
static float mixramp_interpolate(char *ramp_list, float required_db)
......@@ -123,14 +125,16 @@ unsigned cross_fade_calc(float duration, float total_time,
if (!std::isnan(mixramp_overlap) &&
mixramp_delay <= mixramp_overlap) {
chunks = (chunks_f * (mixramp_overlap - mixramp_delay));
g_debug("will overlap %d chunks, %fs", chunks,
mixramp_overlap - mixramp_delay);
FormatDebug(cross_fade_domain,
"will overlap %d chunks, %fs", chunks,
mixramp_overlap - mixramp_delay);
}
}
if (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;
......
......@@ -22,6 +22,8 @@
#include "system/FatalError.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -39,8 +41,7 @@
#include <grp.h>
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "daemon"
static constexpr Domain daemon_domain("daemon");
#ifndef WIN32
......@@ -170,7 +171,7 @@ daemonize_detach(void)
FatalError("no support for daemonizing");
#endif
g_debug("daemonized!");
LogDebug(daemon_domain, "daemonized");
}
void
......@@ -181,7 +182,7 @@ daemonize(bool detach)
if (!pidfile.IsNull()) {
/* do this before daemon'izing so we can fail gracefully if we can't
* write to the pid file */
g_debug("opening pid file");
LogDebug(daemon_domain, "opening pid file");
fp = FOpen(pidfile, "w+");
if (!fp) {
const std::string utf8 = pidfile.ToUTF8();
......@@ -194,7 +195,7 @@ daemonize(bool detach)
daemonize_detach();
if (!pidfile.IsNull()) {
g_debug("writing pid file");
LogDebug(daemon_domain, "writing pid file");
fprintf(fp, "%lu\n", (unsigned long)getpid());
fclose(fp);
}
......
......@@ -43,9 +43,6 @@ extern "C" {
#include <string.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "database"
static Database *db;
static bool db_is_open;
static bool is_simple;
......
......@@ -29,15 +29,13 @@
#include "tag/TagSettings.h"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "database"
#define DIRECTORY_INFO_BEGIN "info_begin"
#define DIRECTORY_INFO_END "info_end"
#define DB_FORMAT_PREFIX "format: "
......@@ -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();
success = directory_load(file, music_root, error);
......
......@@ -19,6 +19,7 @@
#include "config.h"
#include "DecoderAPI.hxx"
#include "DecoderError.hxx"
#include "AudioConfig.hxx"
#include "replay_gain_config.h"
#include "MusicChunk.hxx"
......@@ -29,16 +30,12 @@
#include "Song.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include "Log.hxx"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder"
void
decoder_initialized(struct decoder *decoder,
const AudioFormat audio_format,
......@@ -67,14 +64,14 @@ decoder_initialized(struct decoder *decoder,
dc->client_cond.signal();
dc->Unlock();
g_debug("audio_format=%s, seekable=%s",
audio_format_to_string(dc->in_audio_format, &af_string),
seekable ? "true" : "false");
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
audio_format_to_string(dc->in_audio_format, &af_string),
seekable ? "true" : "false");
if (dc->in_audio_format != dc->out_audio_format)
g_debug("converting to %s",
audio_format_to_string(dc->out_audio_format,
&af_string));
FormatDebug(decoder_domain, "converting to %s",
audio_format_to_string(dc->out_audio_format,
&af_string));
}
/**
......@@ -288,7 +285,7 @@ size_t decoder_read(struct decoder *decoder,
assert(nbytes > 0 || error.IsDefined() || is->IsEOF());
if (gcc_unlikely(nbytes == 0 && error.IsDefined()))
g_warning("%s", error.GetMessage());
LogError(error);
is->Unlock();
......@@ -404,7 +401,7 @@ decoder_data(struct decoder *decoder,
/* the PCM conversion has failed - stop
playback, since we have no better way to
bail out */
g_warning("%s", error.GetMessage());
LogError(error);
return DecoderCommand::STOP;
}
}
......
......@@ -26,9 +26,6 @@
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder_control"
decoder_control::decoder_control()
:thread(nullptr),
state(DecoderState::STOP),
......
......@@ -33,15 +33,16 @@
#include "DecoderList.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "tag/ApeReplayGain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder_thread"
static constexpr Domain decoder_thread_domain("decoder_thread");
/**
* 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)
input_stream *is = input_stream::Open(uri, dc->mutex, dc->cond, error);
if (is == NULL) {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
LogError(error);
return NULL;
}
......@@ -99,7 +100,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
if (!is->Check(error)) {
dc->Unlock();
g_warning("%s", error.GetMessage());
LogError(error);
return NULL;
}
......@@ -122,7 +123,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
assert(input_stream->ready);
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)
return true;
......@@ -155,7 +156,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
assert(g_path_is_absolute(path));
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)
return true;
......
......@@ -21,13 +21,15 @@
#include "tag/Tag.hxx"
#include "ConfigGlobal.hxx"
#include "ConfigOption.hxx"
#include <glib.h>
#include "util/Domain.hxx"
#include "Log.hxx"
extern "C" {
#include <despotify.h>
}
const Domain despotify_domain("despotify");
static struct despotify_session *g_session;
static void (*registered_callbacks[8])(struct despotify_session *,
int, void *, void *);
......@@ -121,24 +123,27 @@ struct despotify_session *mpd_despotify_get_session(void)
high_bitrate = config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true);
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;
}
if (!despotify_init()) {
g_debug("Can't initialize despotify\n");
LogWarning(despotify_domain, "Can't initialize despotify");
return nullptr;
}
g_session = despotify_init_client(callback, NULL,
high_bitrate, true);
if (!g_session) {
g_debug("Can't initialize despotify client\n");
LogWarning(despotify_domain,
"Can't initialize despotify client");
return nullptr;
}
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);
return nullptr;
}
......
......@@ -24,6 +24,8 @@ struct Tag;
struct despotify_session;
struct ds_track;
extern const class Domain despotify_domain;
/**
* Return the current despotify session.
*
......
/*
* Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
......@@ -26,21 +27,26 @@
#include "ExcludeList.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#include <errno.h>
static constexpr Domain exclude_list_domain("exclude_list");
bool
ExcludeList::LoadFile(const Path &path_fs)
{
FILE *file = FOpen(path_fs, FOpenMode::ReadText);
if (file == NULL) {
if (errno != ENOENT) {
const char *msg = g_strerror(errno);
const int e = errno;
if (e != ENOENT) {
const auto path_utf8 = path_fs.ToUTF8();
g_debug("Failed to open %s: %s",
path_utf8.c_str(), msg);
FormatErrno(exclude_list_domain,
"Failed to open %s",
path_utf8.c_str());
}
return false;
......
......@@ -28,9 +28,6 @@
#include <assert.h>
#include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "global_events"
namespace GlobalEvents {
class Monitor final : public DeferredMonitor {
public:
......
......@@ -20,14 +20,15 @@
#include "config.h"
#include "IcyMetaDataParser.hxx"
#include "tag/Tag.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "icy_metadata"
static constexpr Domain icy_metadata_domain("icy_metadata");
void
IcyMetaDataParser::Reset()
......@@ -88,7 +89,8 @@ icy_parse_tag_item(Tag &tag, const char *item)
if (strcmp(p[0], "StreamTitle") == 0)
icy_add_item(tag, TAG_TITLE, p[1]);
else
g_debug("unknown icy-tag: '%s'", p[0]);
FormatDebug(icy_metadata_domain,
"unknown icy-tag: '%s'", p[0]);
}
g_strfreev(p);
......
......@@ -27,9 +27,6 @@
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "icy_server"
char*
icy_server_metadata_header(const char *name,
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 @@
#include "config.h"
#include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "UpdateGlue.hxx"
#include "event/Loop.hxx"
#include <glib.h>
#include "Log.hxx"
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
enum {
/**
* Wait this long after the last change before calling
......@@ -53,7 +50,8 @@ InotifyQueue::OnTimeout()
return;
}
g_debug("updating '%s' job=%u", uri_utf8, id);
FormatDebug(inotify_domain, "updating '%s' job=%u",
uri_utf8, id);
queue.pop_front();
}
......
......@@ -19,19 +19,17 @@
#include "config.h"
#include "InotifySource.hxx"
#include "InotifyDomain.hxx"
#include "util/fifo_buffer.h"
#include "util/Error.hxx"
#include "system/fd_util.h"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include <glib.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
bool
InotifySource::OnSocketReady(gcc_unused unsigned flags)
......@@ -120,8 +118,7 @@ InotifySource::Remove(unsigned wd)
{
int ret = inotify_rm_watch(Get(), wd);
if (ret < 0 && errno != EINVAL)
g_warning("inotify_rm_watch() has failed: %s",
g_strerror(errno));
LogErrno(inotify_domain, "inotify_rm_watch() has failed");
/* EINVAL may happen here when the file has been deleted; the
kernel seems to auto-unregister deleted files */
......
......@@ -21,10 +21,12 @@
#include "InotifyUpdate.hxx"
#include "InotifySource.hxx"
#include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "Mapper.hxx"
#include "Main.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -36,10 +38,6 @@
#include <sys/stat.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "inotify"
enum {
IN_MASK = IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF
......@@ -120,8 +118,9 @@ remove_watch_directory(WatchDirectory *directory)
assert(directory != NULL);
if (directory->parent == NULL) {
g_warning("music directory was removed - "
"cannot continue to watch it");
LogWarning(inotify_domain,
"music directory was removed - "
"cannot continue to watch it");
return;
}
......@@ -178,8 +177,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
dir = opendir(path_fs);
if (dir == NULL) {
g_warning("Failed to open directory %s: %s",
path_fs, g_strerror(errno));
FormatErrno(inotify_domain,
"Failed to open directory %s", path_fs);
return;
}
......@@ -194,8 +193,9 @@ recursive_watch_subdirectories(WatchDirectory *directory,
child_path_fs = g_strconcat(path_fs, "/", ent->d_name, NULL);
ret = stat(child_path_fs, &st);
if (ret < 0) {
g_warning("Failed to stat %s: %s",
child_path_fs, g_strerror(errno));
FormatErrno(inotify_domain,
"Failed to stat %s",
child_path_fs);
g_free(child_path_fs);
continue;
}
......@@ -207,8 +207,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
ret = inotify_source->Add(child_path_fs, IN_MASK, error);
if (ret < 0) {
g_warning("Failed to register %s: %s",
child_path_fs, error.GetMessage());
FormatError(error,
"Failed to register %s", child_path_fs);
error.Clear();
g_free(child_path_fs);
continue;
......@@ -253,7 +253,7 @@ mpd_inotify_callback(int wd, unsigned mask,
WatchDirectory *directory;
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);
if (directory == NULL)
......@@ -309,11 +309,11 @@ mpd_inotify_callback(int wd, unsigned mask,
void
mpd_inotify_init(unsigned max_depth)
{
g_debug("initializing inotify");
LogDebug(inotify_domain, "initializing inotify");
const Path &path = mapper_get_music_directory_fs();
if (path.IsNull()) {
g_debug("no music directory configured");
LogDebug(inotify_domain, "no music directory configured");
return;
}
......@@ -322,7 +322,7 @@ mpd_inotify_init(unsigned max_depth)
mpd_inotify_callback, nullptr,
error);
if (inotify_source == NULL) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
......@@ -330,7 +330,7 @@ mpd_inotify_init(unsigned max_depth)
int descriptor = inotify_source->Add(path.c_str(), IN_MASK, error);
if (descriptor < 0) {
g_warning("%s", error.GetMessage());
LogError(error);
delete inotify_source;
inotify_source = NULL;
return;
......@@ -344,7 +344,7 @@ mpd_inotify_init(unsigned max_depth)
inotify_queue = new InotifyQueue(*main_loop);
g_debug("watching music directory");
LogDebug(inotify_domain, "watching music directory");
}
void
......
......@@ -27,7 +27,9 @@
#include "ConfigOption.hxx"
#include "event/ServerSocket.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -38,8 +40,7 @@
#include <systemd/sd-daemon.h>
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "listen"
static constexpr Domain listen_domain("listen");
#define DEFAULT_PORT 6600
......@@ -82,8 +83,8 @@ listen_systemd_activation(Error &error_r)
int n = sd_listen_fds(true);
if (n <= 0) {
if (n < 0)
g_warning("sd_listen_fds() failed: %s",
g_strerror(-n));
FormatErrno(listen_domain, -n,
"sd_listen_fds() failed");
return false;
}
......@@ -155,7 +156,7 @@ listen_global_init(Error &error)
void listen_global_finish(void)
{
g_debug("listen_global_finish called");
LogDebug(listen_domain, "listen_global_finish called");
assert(listen_socket != NULL);
......
......@@ -18,7 +18,7 @@
*/
#include "config.h"
#include "Log.hxx"
#include "LogV.hxx"
#include "ConfigData.hxx"
#include "ConfigGlobal.hxx"
#include "ConfigOption.hxx"
......@@ -30,322 +30,157 @@
#include "util/Domain.hxx"
#include "system/FatalError.hxx"
#include <glib.h>
#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
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "log"
#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 GLogLevelFlags
ToGLib(LogLevel level)
{
switch (level) {
case LogLevel::DEBUG:
return G_LOG_LEVEL_DEBUG;
static const char *log_charset;
case LogLevel::INFO:
return G_LOG_LEVEL_MESSAGE;
static bool stdout_mode = true;
static int out_fd;
static Path out_path = Path::Null();
case LogLevel::WARNING:
case LogLevel::ERROR:
return G_LOG_LEVEL_WARNING;
}
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");
assert(false);
gcc_unreachable();
}
static const char *log_date(void)
void
Log(const Domain &domain, LogLevel level, const char *msg)
{
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;
g_log(domain.GetName(), ToGLib(level), "%s", msg);
}
/**
* Determines the length of the string excluding trailing whitespace
* characters.
*/
static int
chomp_length(const char *p)
void
LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap)
{
size_t length = strlen(p);
while (length > 0 && g_ascii_isspace(p[length - 1]))
--length;
return (int)length;
g_logv(domain.GetName(), ToGLib(level), fmt, ap);
}
static void
file_log_func(const gchar *domain,
GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
void
LogFormat(const Domain &domain, LogLevel level, const char *fmt, ...)
{
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);
va_list ap;
va_start(ap, fmt);
LogFormatV(domain, level, fmt, ap);
va_end(ap);
}
static void
log_init_stdout(void)
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
open_log_file(void)
void
FormatInfo(const Domain &domain, const char *fmt, ...)
{
assert(!out_path.IsNull());
return OpenFile(out_path, O_CREAT | O_WRONLY | O_APPEND, 0666);
va_list ap;
va_start(ap, fmt);
LogFormatV(domain, LogLevel::INFO, fmt, ap);
va_end(ap);
}
static bool
log_init_file(unsigned line, Error &error)
void
FormatWarning(const Domain &domain, const char *fmt, ...)
{
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;
va_list ap;
va_start(ap, fmt);
LogFormatV(domain, LogLevel::WARNING, fmt, ap);
va_end(ap);
}
#ifdef HAVE_SYSLOG
static int
glib_to_syslog_level(GLogLevelFlags log_level)
void
FormatError(const Domain &domain, const char *fmt, ...)
{
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;
}
va_list ap;
va_start(ap, fmt);
LogFormatV(domain, LogLevel::ERROR, fmt, ap);
va_end(ap);
}
static void
syslog_log_func(const gchar *domain,
GLogLevelFlags log_level, const gchar *message,
gcc_unused gpointer user_data)
void
LogError(const Error &error)
{
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);
Log(error.GetDomain(), LogLevel::ERROR, error.GetMessage());
}
static void
log_init_syslog(void)
void
LogError(const Error &error, const char *msg)
{
assert(out_path.IsNull());
openlog(PACKAGE, 0, LOG_DAEMON);
g_log_set_default_handler(syslog_log_func, NULL);
LogFormat(error.GetDomain(), LogLevel::ERROR, "%s: %s",
msg, error.GetMessage());
}
#endif
static inline GLogLevelFlags
parse_log_level(const char *value, unsigned line)
void
FormatError(const Error &error, const char *fmt, ...)
{
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;
}
char msg[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
LogError(error, msg);
}
void
log_early_init(bool verbose)
LogErrno(const Domain &domain, int e, const char *msg)
{
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
log_init_stdout();
LogFormat(domain, LogLevel::ERROR, "%s: %s", msg, g_strerror(e));
}
bool
log_init(bool verbose, bool use_stdout, Error &error)
void
LogErrno(const Domain &domain, const char *msg)
{
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);
}
}
LogErrno(domain, errno, msg);
}
static void
close_log_files(void)
FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap)
{
if (stdout_mode)
return;
char msg[1024];
vsnprintf(msg, sizeof(msg), fmt, ap);
#ifdef HAVE_SYSLOG
if (out_path.IsNull())
closelog();
#endif
LogErrno(domain, e, msg);
}
void
log_deinit(void)
FormatErrno(const Domain &domain, int e, const char *fmt, ...)
{
close_log_files();
out_path = Path::Null();
va_list ap;
va_start(ap, fmt);
FormatErrnoV(domain, e, fmt, ap);
va_end(ap);
}
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)
void
FormatErrno(const Domain &domain, const char *fmt, ...)
{
int fd;
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;
}
const int e = errno;
redirect_logs(fd);
g_debug("Done cycling log files\n");
return 0;
va_list ap;
va_start(ap, fmt);
FormatErrnoV(domain, e, fmt, ap);
va_end(ap);
}
......@@ -20,27 +20,95 @@
#ifndef 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 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
log_early_init(bool verbose);
LogError(const Error &error);
bool
log_init(bool verbose, bool use_stdout, Error &error);
void
LogError(const Error &error, const char *msg);
gcc_fprintf
void
FormatError(const Error &error, const char *fmt, ...);
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 */
/*
* 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 @@
#include "Idle.hxx"
#include "SignalHandlers.hxx"
#include "Log.hxx"
#include "LogInit.hxx"
#include "GlobalEvents.hxx"
#include "InputInit.hxx"
#include "event/Loop.hxx"
......@@ -56,6 +57,7 @@
#include "Daemon.hxx"
#include "system/FatalError.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "ConfigGlobal.hxx"
#include "ConfigData.hxx"
#include "ConfigDefaults.hxx"
......@@ -98,6 +100,8 @@ enum {
DEFAULT_BUFFER_BEFORE_PLAY = 10,
};
static constexpr Domain main_domain("main");
GThread *main_task;
EventLoop *main_loop;
......@@ -105,11 +109,6 @@ Instance *instance;
static StateFile *state_file;
static inline GQuark main_quark()
{
return g_quark_from_static_string ("main");
}
static bool
glue_daemonize_init(const struct options *options, Error &error)
{
......@@ -161,15 +160,18 @@ glue_db_init_and_load(void)
const struct config_param *path = config_get_param(CONF_DB_FILE);
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 (param != nullptr)
g_message("Found database setting without "
"music_directory - disabling database");
LogInfo(main_domain,
"Found database setting without "
"music_directory - disabling database");
if (path != nullptr)
g_message("Found db_file setting without "
"music_directory - disabling database");
LogInfo(main_domain,
"Found db_file setting without "
"music_directory - disabling database");
return true;
}
......@@ -372,12 +374,12 @@ int mpd_main(int argc, char *argv[])
success = parse_cmdline(argc, argv, &options, error);
if (!success) {
g_warning("%s", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
if (!glue_daemonize_init(&options, error)) {
g_printerr("%s\n", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -385,7 +387,7 @@ int mpd_main(int argc, char *argv[])
TagLoadConfig();
if (!log_init(options.verbose, options.log_stderr, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -399,7 +401,7 @@ int mpd_main(int argc, char *argv[])
success = listen_global_init(error);
if (!success) {
g_warning("%s", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -414,7 +416,7 @@ int mpd_main(int argc, char *argv[])
Path::GlobalInit();
if (!glue_mapper_init(error)) {
g_printerr("%s\n", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -426,7 +428,7 @@ int mpd_main(int argc, char *argv[])
#endif
if (!pcm_resample_global_init(error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -446,7 +448,7 @@ int mpd_main(int argc, char *argv[])
replay_gain_global_init();
if (!input_stream_global_init(error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return EXIT_FAILURE;
}
......@@ -486,7 +488,8 @@ int mpd_main(int argc, char *argv[])
G_MAXUINT));
#else
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
config_global_check();
......@@ -524,8 +527,9 @@ int mpd_main(int argc, char *argv[])
start = clock();
DatabaseGlobalDeinit();
g_debug("db_finish took %f seconds",
((float)(clock()-start))/CLOCKS_PER_SEC);
FormatDebug(main_domain,
"db_finish took %f seconds",
((float)(clock()-start))/CLOCKS_PER_SEC);
#ifdef ENABLE_SQLITE
sticker_global_finish();
......
......@@ -28,6 +28,8 @@
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -38,6 +40,8 @@
#include <errno.h>
#include <dirent.h>
static constexpr Domain mapper_domain("mapper");
/**
* The absolute path of the music directory encoded in UTF-8.
*/
......@@ -57,12 +61,6 @@ static size_t music_dir_fs_length;
*/
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.
*/
......@@ -82,26 +80,30 @@ check_directory(const char *path_utf8, const Path &path_fs)
{
struct stat st;
if (!StatFile(path_fs, st)) {
g_warning("Failed to stat directory \"%s\": %s",
path_utf8, g_strerror(errno));
FormatErrno(mapper_domain,
"Failed to stat directory \"%s\"",
path_utf8);
return;
}
if (!S_ISDIR(st.st_mode)) {
g_warning("Not a directory: %s", path_utf8);
FormatError(mapper_domain,
"Not a directory: %s", path_utf8);
return;
}
#ifndef WIN32
const Path x = Path::Build(path_fs, ".");
if (!StatFile(x, st) && errno == EACCES)
g_warning("No permission to traverse (\"execute\") directory: %s",
path_utf8);
FormatError(mapper_domain,
"No permission to traverse (\"execute\") directory: %s",
path_utf8);
#endif
const DirectoryReader reader(path_fs);
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
......
......@@ -26,13 +26,12 @@
#include "pcm/PcmVolume.hxx"
#include "OutputInternal.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mixer"
static constexpr Domain mixer_domain("mixer");
static int
output_mixer_get_volume(unsigned i)
......@@ -53,8 +52,9 @@ output_mixer_get_volume(unsigned i)
Error error;
volume = mixer_get_volume(mixer, error);
if (volume < 0 && error.IsDefined())
g_warning("Failed to read mixer for '%s': %s",
output->name, error.GetMessage());
FormatError(error,
"Failed to read mixer for '%s'",
output->name);
return volume;
}
......@@ -99,8 +99,9 @@ output_mixer_set_volume(unsigned i, unsigned volume)
Error error;
success = mixer_set_volume(mixer, volume, error);
if (!success && error.IsDefined())
g_warning("Failed to set mixer for '%s': %s",
output->name, error.GetMessage());
FormatError(error,
"Failed to set mixer for '%s'",
output->name);
return success;
}
......
......@@ -25,9 +25,6 @@
#include <assert.h>
#include <stddef.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mixer"
Mixer *
mixer_new(const struct mixer_plugin *plugin, void *ao,
const config_param &param,
......
......@@ -36,9 +36,6 @@
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "output"
static AudioFormat input_audio_format;
static struct audio_output **audio_outputs;
......
......@@ -22,12 +22,14 @@
#include "OutputThread.hxx"
#include "OutputInternal.hxx"
#include "OutputPlugin.hxx"
#include "OutputError.hxx"
#include "MixerPlugin.hxx"
#include "MixerControl.hxx"
#include "notify.hxx"
#include "filter/ReplayGainFilterPlugin.hxx"
#include "FilterPlugin.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -191,8 +193,9 @@ audio_output_open(struct audio_output *ao,
if (open && ao->mixer != NULL) {
Error error;
if (!mixer_open(ao->mixer, error))
g_warning("Failed to open mixer for '%s': %s",
ao->name, error.GetMessage());
FormatWarning(output_domain,
"Failed to open mixer for '%s'",
ao->name);
}
return open;
......
......@@ -37,15 +37,11 @@
#include "ConfigError.hxx"
#include "ConfigGlobal.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "output"
#define AUDIO_OUTPUT_TYPE "type"
#define AUDIO_OUTPUT_NAME "name"
#define AUDIO_OUTPUT_FORMAT "format"
......@@ -54,14 +50,15 @@
static const struct audio_output_plugin *
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) {
if (plugin->test_default_device == NULL)
continue;
g_warning("Attempting to detect a %s audio device",
plugin->name);
FormatInfo(output_domain,
"Attempting to detect a %s audio device",
plugin->name);
if (ao_plugin_test_default_device(plugin))
return plugin;
}
......@@ -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
// and even an empty one will work (if only with unexpected behaviour)
if (filter_error.IsDefined())
g_warning("Failed to initialize filter chain for '%s': %s",
ao->name, filter_error.GetMessage());
FormatError(filter_error,
"Failed to initialize filter chain for '%s'",
ao->name);
ao->thread = NULL;
ao->command = AO_COMMAND_NONE;
......@@ -251,8 +249,9 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
ao->plugin->mixer_plugin,
*ao->filter, mixer_error);
if (ao->mixer == NULL && mixer_error.IsDefined())
g_warning("Failed to initialize hardware mixer for '%s': %s",
ao->name, mixer_error.GetMessage());
FormatError(mixer_error,
"Failed to initialize hardware mixer for '%s'",
ao->name);
/* use the hardware mixer for replay gain? */
......@@ -261,7 +260,8 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
replay_gain_filter_set_mixer(ao->replay_gain_filter,
ao->mixer, 100);
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 &&
ao->replay_gain_filter != NULL) {
error.Set(config_domain,
......@@ -304,14 +304,16 @@ audio_output_new(const config_param &param,
return nullptr;
}
} 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);
if (plugin == NULL)
return nullptr;
g_message("Successfully detected a %s audio device",
plugin->name);
FormatInfo(output_domain,
"Successfully detected a %s audio device",
plugin->name);
}
struct audio_output *ao = ao_plugin_init(plugin, param, error);
......
......@@ -26,6 +26,8 @@
#include "OutputState.hxx"
#include "OutputAll.hxx"
#include "OutputInternal.hxx"
#include "OutputError.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -76,7 +78,8 @@ audio_output_state_read(const char *line)
name = endptr + 1;
ao = audio_output_find(name);
if (ao == NULL) {
g_debug("Ignoring device state for '%s'", name);
FormatDebug(output_domain,
"Ignoring device state for '%s'", name);
return true;
}
......
......@@ -21,6 +21,7 @@
#include "OutputThread.hxx"
#include "OutputInternal.hxx"
#include "OutputAPI.hxx"
#include "OutputError.hxx"
#include "pcm/PcmMix.hxx"
#include "notify.hxx"
#include "FilterInternal.hxx"
......@@ -31,17 +32,13 @@
#include "MusicChunk.hxx"
#include "system/FatalError.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include "gcc.h"
#include <glib.h>
#include <assert.h>
#include <stdlib.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)
{
......@@ -66,8 +63,9 @@ ao_enable(struct audio_output *ao)
success = ao_plugin_enable(ao, error);
ao->mutex.lock();
if (!success) {
g_warning("Failed to enable \"%s\" [%s]: %s\n",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error,
"Failed to enable \"%s\" [%s]",
ao->name, ao->plugin->name);
return false;
}
......@@ -159,8 +157,8 @@ ao_open(struct audio_output *ao)
const AudioFormat filter_audio_format =
ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) {
g_warning("Failed to open filter for \"%s\" [%s]: %s",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error, "Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->fail_timer = g_timer_new();
return;
......@@ -178,8 +176,8 @@ ao_open(struct audio_output *ao)
assert(!ao->open);
if (!success) {
g_warning("Failed to open \"%s\" [%s]: %s",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error, "Failed to open \"%s\" [%s]",
ao->name, ao->plugin->name);
ao_filter_close(ao);
ao->fail_timer = g_timer_new();
......@@ -190,15 +188,15 @@ ao_open(struct audio_output *ao)
ao->open = true;
g_debug("opened plugin=%s name=\"%s\" "
"audio_format=%s",
ao->plugin->name, ao->name,
audio_format_to_string(ao->out_audio_format, &af_string));
FormatDebug(output_domain,
"opened plugin=%s name=\"%s\" audio_format=%s",
ao->plugin->name, ao->name,
audio_format_to_string(ao->out_audio_format, &af_string));
if (ao->in_audio_format != ao->out_audio_format)
g_debug("converting from %s",
audio_format_to_string(ao->in_audio_format,
&af_string));
FormatDebug(output_domain, "converting from %s",
audio_format_to_string(ao->in_audio_format,
&af_string));
}
static void
......@@ -223,7 +221,8 @@ ao_close(struct audio_output *ao, bool drain)
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
......@@ -235,8 +234,9 @@ ao_reopen_filter(struct audio_output *ao)
const AudioFormat filter_audio_format =
ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) {
g_warning("Failed to open filter for \"%s\" [%s]: %s",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error,
"Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name);
/* this is a little code duplication fro ao_close(),
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,
data = replay_gain_filter->FilterPCM(data, length,
&length, error);
if (data == NULL) {
g_warning("\"%s\" [%s] failed to filter: %s",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name);
return NULL;
}
}
......@@ -390,8 +390,9 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
if (!pcm_mix(dest, data, length,
ao->in_audio_format.format,
1.0 - chunk->mix_ratio)) {
g_warning("Cannot cross-fade format %s",
sample_format_to_string(ao->in_audio_format.format));
FormatError(output_domain,
"Cannot cross-fade format %s",
sample_format_to_string(ao->in_audio_format.format));
return NULL;
}
......@@ -404,8 +405,8 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
Error error;
data = ao->filter->FilterPCM(data, length, &length, error);
if (data == NULL) {
g_warning("\"%s\" [%s] failed to filter: %s",
ao->name, ao->plugin->name, error.GetMessage());
FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name);
return NULL;
}
......@@ -453,9 +454,8 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk)
ao->mutex.lock();
if (nbytes == 0) {
/* play()==0 means failure */
g_warning("\"%s\" [%s] failed to play: %s",
ao->name, ao->plugin->name,
error.GetMessage());
FormatError(error, "\"%s\" [%s] failed to play",
ao->name, ao->plugin->name);
ao_close(ao, false);
......
......@@ -33,6 +33,8 @@
#include "tag/Tag.hxx"
#include "Idle.hxx"
#include "GlobalEvents.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <cmath>
......@@ -40,8 +42,7 @@
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "player_thread"
static constexpr Domain player_domain("player");
enum class CrossFadeState : int8_t {
DISABLED = -1,
......@@ -402,7 +403,7 @@ Player::OpenOutput()
return true;
} else {
g_warning("%s", error.GetMessage());
LogError(error);
output_open = false;
......@@ -461,8 +462,9 @@ Player::CheckDecoderStartup()
if (!paused && !OpenOutput()) {
char *uri = dc.song->GetURI();
g_warning("problems opening audio device "
"while playing \"%s\"", uri);
FormatError(player_domain,
"problems opening audio device "
"while playing \"%s\"", uri);
g_free(uri);
return true;
......@@ -487,7 +489,7 @@ Player::SendSilence()
struct music_chunk *chunk = buffer.Allocate();
if (chunk == nullptr) {
g_warning("Failed to allocate silence buffer");
LogError(player_domain, "Failed to allocate silence buffer");
return false;
}
......@@ -506,7 +508,7 @@ Player::SendSilence()
Error error;
if (!audio_output_all_play(chunk, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
buffer.Return(chunk);
return false;
}
......@@ -838,7 +840,7 @@ Player::PlayNextChunk()
Error error;
if (!play_chunk(pc, song, chunk, buffer, play_audio_format, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
buffer.Return(chunk);
......@@ -877,7 +879,7 @@ Player::SongBorder()
xfade_state = CrossFadeState::UNKNOWN;
char *uri = song->GetURI();
g_message("played \"%s\"", uri);
FormatInfo(player_domain, "played \"%s\"", uri);
g_free(uri);
ReplacePipe(dc.pipe);
......
......@@ -19,17 +19,16 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx"
#include "Song.hxx"
#include "Idle.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "playlist"
void
playlist::FullIncrementVersions()
{
......@@ -65,7 +64,8 @@ playlist_queue_song_order(struct playlist *playlist, struct player_control *pc,
Song *song = playlist->queue.GetOrder(order)->DupDetached();
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);
pc->EnqueueSong(song);
......@@ -156,7 +156,7 @@ playlist::PlayOrder(player_control &pc, int order)
Song *song = queue.GetOrder(order)->DupDetached();
char *uri = song->GetURI();
g_debug("play %i:\"%s\"", order, uri);
FormatDebug(playlist_domain, "play %i:\"%s\"", order, uri);
g_free(uri);
pc.Play(song);
......
......@@ -21,9 +21,11 @@
#include "PlaylistAny.hxx"
#include "PlaylistMapper.hxx"
#include "PlaylistRegistry.hxx"
#include "PlaylistError.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "InputStream.hxx"
#include "Log.hxx"
#include <assert.h>
......@@ -43,8 +45,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
input_stream *is = input_stream::Open(uri, mutex, cond, error);
if (is == nullptr) {
if (error.IsDefined())
g_warning("Failed to open %s: %s",
uri, error.GetMessage());
FormatError(error, "Failed to open %s", uri);
return nullptr;
}
......
......@@ -24,13 +24,10 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx"
#include "Song.hxx"
#include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "playlist"
#include "Log.hxx"
void
playlist::Stop(player_control &pc)
......@@ -40,7 +37,7 @@ playlist::Stop(player_control &pc)
assert(current >= 0);
g_debug("stop");
FormatDebug(playlist_domain, "stop");
pc.Stop();
queued = -1;
playing = false;
......
......@@ -25,6 +25,7 @@
#include "config.h"
#include "Playlist.hxx"
#include "PlaylistError.hxx"
#include "PlayerControl.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
......@@ -32,6 +33,7 @@
#include "Idle.hxx"
#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include "Log.hxx"
#include <stdlib.h>
......@@ -104,7 +106,7 @@ enum playlist_result
playlist::AppendURI(struct player_control &pc,
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;
Song *song;
......
......@@ -37,6 +37,7 @@
#include "ConfigGlobal.hxx"
#include "ConfigData.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include <assert.h>
#include <string.h>
......@@ -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);
if (is == nullptr) {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
LogError(error);
return nullptr;
}
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include "PlaylistSave.hxx"
#include "PlaylistFile.hxx"
#include "PlaylistError.hxx"
#include "Playlist.hxx"
#include "Song.hxx"
#include "Mapper.hxx"
......@@ -28,6 +29,7 @@
#include "fs/FileSystem.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -123,7 +125,8 @@ playlist_load_spl(struct playlist *playlist, struct player_control *pc,
}
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);
}
......
......@@ -24,12 +24,14 @@
#include "config.h"
#include "PlaylistState.hxx"
#include "PlaylistError.hxx"
#include "Playlist.hxx"
#include "QueueSave.hxx"
#include "TextFile.hxx"
#include "PlayerControl.hxx"
#include "ConfigGlobal.hxx"
#include "ConfigOption.hxx"
#include "Log.hxx"
#include <string.h>
#include <stdlib.h>
......@@ -102,7 +104,7 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
{
const char *line = file.ReadLine();
if (line == nullptr) {
g_warning("No playlist in state file");
LogWarning(playlist_domain, "No playlist in state file");
return;
}
......@@ -111,8 +113,9 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
line = file.ReadLine();
if (line == nullptr) {
g_warning("'" PLAYLIST_STATE_FILE_PLAYLIST_END
"' not found in state file");
LogWarning(playlist_domain,
"'" PLAYLIST_STATE_FILE_PLAYLIST_END
"' not found in state file");
break;
}
}
......
......@@ -19,7 +19,8 @@
#include "config.h"
#include "QueueSave.hxx"
#include "Playlist.hxx"
#include "Queue.hxx"
#include "PlaylistError.hxx"
#include "Song.hxx"
#include "SongSave.hxx"
#include "DatabasePlugin.hxx"
......@@ -27,6 +28,7 @@
#include "TextFile.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -96,14 +98,15 @@ queue_load_song(TextFile &file, const char *line, queue *queue)
Error error;
song = song_load(file, NULL, uri, error);
if (song == NULL) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
} else {
char *endptr;
long ret = strtol(line, &endptr, 10);
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;
}
......
......@@ -24,15 +24,17 @@
#ifndef WIN32
#include "Log.hxx"
#include "LogInit.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include "GlobalEvents.hxx"
#include "system/FatalError.hxx"
#include <glib.h>
#include "util/Domain.hxx"
#include <signal.h>
static constexpr Domain signal_handlers_domain("signal_handlers");
static EventLoop *shutdown_loop;
static void
......@@ -51,7 +53,7 @@ x_sigaction(int signum, const struct sigaction *act)
static void
handle_reload_event(void)
{
g_debug("got SIGHUP, reopening log files");
LogDebug(signal_handlers_domain, "got SIGHUP, reopening log files");
cycle_log_files();
}
......
......@@ -29,13 +29,8 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include <glib.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "song"
#define SONG_MTIME "mtime"
#define SONG_END "song_end"
......
......@@ -26,14 +26,12 @@
#include "Volume.hxx"
#include "event/Loop.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
#include "util/Domain.hxx"
#include "Log.hxx"
#include <string.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "state_file"
static constexpr Domain state_file_domain("state_file");
StateFile::StateFile(Path &&_path,
Partition &_partition, EventLoop &_loop)
......@@ -66,12 +64,13 @@ StateFile::IsModified() const
void
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);
if (G_UNLIKELY(!fp)) {
g_warning("failed to create %s: %s",
path_utf8.c_str(), g_strerror(errno));
if (gcc_unlikely(!fp)) {
FormatErrno(state_file_domain, "failed to create %s",
path_utf8.c_str());
return;
}
......@@ -89,12 +88,12 @@ StateFile::Read()
{
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);
if (file.HasFailed()) {
g_warning("failed to open %s: %s",
path_utf8.c_str(), g_strerror(errno));
FormatErrno(state_file_domain, "failed to open %s",
path_utf8.c_str());
return;
}
......@@ -105,7 +104,9 @@ StateFile::Read()
playlist_state_restore(line, file, &partition.playlist,
&partition.pc);
if (!success)
g_warning("Unrecognized line in state file: %s", line);
FormatError(state_file_domain,
"Unrecognized line in state file: %s",
line);
}
RememberVersions();
......
......@@ -30,6 +30,7 @@ extern "C" {
#include "DatabasePlugin.hxx"
#include "DatabaseSimple.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
struct stats stats;
......@@ -56,7 +57,7 @@ void stats_update(void)
stats.artist_count = stats2.artist_count;
stats.album_count = stats2.album_count;
} else {
g_warning("%s", error.GetMessage());
LogError(error);
stats.song_count = 0;
stats.song_duration = 0;
......
......@@ -23,6 +23,7 @@
#include "Idle.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <string>
#include <map>
......@@ -31,9 +32,6 @@
#include <sqlite3.h>
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "sticker"
#if SQLITE_VERSION_NUMBER < 3003009
#define sqlite3_prepare_v2 sqlite3_prepare
#endif
......@@ -85,6 +83,12 @@ static sqlite3_stmt *sticker_stmt[G_N_ELEMENTS(sticker_sql)];
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 *
sticker_prepare(const char *sql, Error &error)
{
......@@ -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);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return NULL;
}
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return NULL;
}
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return NULL;
}
......@@ -217,8 +218,7 @@ sticker_load_value(const char *type, const char *uri, const char *name)
value = NULL;
} else {
/* error */
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return NULL;
}
......@@ -243,15 +243,13 @@ sticker_list_values(std::map<std::string, std::string> &table,
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -272,8 +270,7 @@ sticker_list_values(std::map<std::string, std::string> &table,
/* no op */
break;
default:
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
} while (ret != SQLITE_DONE);
......@@ -303,29 +300,25 @@ sticker_update_value(const char *type, const char *uri,
ret = sqlite3_bind_text(stmt, 1, value, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 2, type, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 3, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 4, name, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -334,8 +327,7 @@ sticker_update_value(const char *type, const char *uri,
} while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
......@@ -367,29 +359,25 @@ sticker_insert_value(const char *type, const char *uri,
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 4, value, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -398,8 +386,7 @@ sticker_insert_value(const char *type, const char *uri,
} while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
......@@ -442,15 +429,13 @@ sticker_delete(const char *type, const char *uri)
ret = sqlite3_bind_text(stmt, 1, type, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -459,8 +444,7 @@ sticker_delete(const char *type, const char *uri)
} while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
......@@ -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);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 2, uri, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -509,8 +490,7 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
} while (ret == SQLITE_BUSY);
if (ret != SQLITE_DONE) {
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
......@@ -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);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -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);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
ret = sqlite3_bind_text(stmt, 3, name, -1, NULL);
if (ret != SQLITE_OK) {
g_warning("sqlite3_bind_text() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_bind_text() failed");
return false;
}
......@@ -618,8 +595,7 @@ sticker_find(const char *type, const char *base_uri, const char *name,
/* no op */
break;
default:
g_warning("sqlite3_step() failed: %s",
sqlite3_errmsg(sticker_db));
LogError(sticker_db, "sqlite3_step() failed");
return false;
}
} while (ret != SQLITE_DONE);
......
......@@ -22,6 +22,7 @@
#include "InputStream.hxx"
#include "util/fifo_buffer.h"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -58,7 +59,7 @@ bool TextInputStream::ReadLine(std::string &line)
if (nbytes > 0)
fifo_buffer_append(buffer, nbytes);
else if (error.IsDefined()) {
g_warning("%s", error.GetMessage());
LogError(error);
return false;
}
} else
......
......@@ -20,6 +20,7 @@
#include "config.h" /* must be first for large file support */
#include "UpdateArchive.hxx"
#include "UpdateInternal.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx"
#include "Directory.hxx"
#include "Song.hxx"
......@@ -30,6 +31,7 @@
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -53,7 +55,8 @@ update_archive_tree(Directory *directory, const char *name)
update_archive_tree(subdir, tmp+1);
} else {
if (strlen(name) == 0) {
g_warning("archive returned directory only");
LogWarning(update_domain,
"archive returned directory only");
return;
}
......@@ -69,8 +72,8 @@ update_archive_tree(Directory *directory, const char *name)
db_unlock();
modified = true;
g_message("added %s/%s",
directory->GetPath(), name);
FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), name);
}
}
}
......@@ -105,14 +108,15 @@ update_archive_file2(Directory *parent, const char *name,
Error error;
ArchiveFile *file = archive_file_open(plugin, path_fs.c_str(), error);
if (file == NULL) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
g_debug("archive %s opened", path_fs.c_str());
FormatDebug(update_domain, "archive %s opened", path_fs.c_str());
if (directory == NULL) {
g_debug("creating archive directory: %s", name);
FormatDebug(update_domain,
"creating archive directory: %s", name);
db_lock();
directory = parent->CreateChild(name);
/* mark this directory as archive (we use device for
......@@ -131,7 +135,8 @@ update_archive_file2(Directory *parent, const char *name,
:directory(_directory) {}
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);
}
};
......
......@@ -21,6 +21,7 @@
#include "UpdateContainer.hxx"
#include "UpdateInternal.hxx"
#include "UpdateDatabase.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx"
#include "Directory.hxx"
#include "Song.hxx"
......@@ -29,6 +30,7 @@
#include "fs/Path.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagBuilder.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -110,7 +112,8 @@ update_container_file(Directory *directory,
modified = true;
g_message("added %s/%s", directory->GetPath(), vtrack);
FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), 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 @@
#include "UpdateQueue.hxx"
#include "UpdateWalk.hxx"
#include "UpdateRemove.hxx"
#include "UpdateDomain.hxx"
#include "Mapper.hxx"
#include "DatabaseSimple.hxx"
#include "Idle.hxx"
#include "GlobalEvents.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
extern "C" {
#include "stats.h"
......@@ -40,9 +42,6 @@ extern "C" {
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "update"
static enum update_progress {
UPDATE_PROGRESS_IDLE = 0,
UPDATE_PROGRESS_RUNNING = 1,
......@@ -71,23 +70,22 @@ static void * update_task(void *_path)
const char *path = (const char *)_path;
if (path != NULL && *path != 0)
g_debug("starting: %s", path);
FormatDebug(update_domain, "starting: %s", path);
else
g_debug("starting");
LogDebug(update_domain, "starting");
modified = update_walk(path, discard);
if (modified || !db_exists()) {
Error error;
if (!db_save(error))
g_warning("Failed to save database: %s",
error.GetMessage());
LogError(error, "Failed to save database");
}
if (path != NULL && *path != 0)
g_debug("finished: %s", path);
FormatDebug(update_domain, "finished: %s", path);
else
g_debug("finished");
LogDebug(update_domain, "finished");
g_free(_path);
progress = UPDATE_PROGRESS_DONE;
......@@ -104,7 +102,7 @@ spawn_update_task(const char *path)
modified = false;
#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
GError *e = NULL;
update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
......@@ -114,7 +112,8 @@ spawn_update_task(const char *path)
if (++update_task_id > update_task_id_max)
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
......
......@@ -19,12 +19,12 @@
#include "config.h" /* must be first for large file support */
#include "UpdateIO.hxx"
#include "src/UpdateDomain.hxx"
#include "Directory.hxx"
#include "Mapper.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
#include "Log.hxx"
#include <errno.h>
#include <unistd.h>
......@@ -39,8 +39,8 @@ stat_directory(const Directory *directory, struct stat *st)
if (!StatFile(path_fs, *st)) {
int error = errno;
const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s",
path_utf8.c_str(), g_strerror(error));
FormatErrno(update_domain, error,
"Failed to stat %s", path_utf8.c_str());
return -1;
}
......@@ -58,8 +58,8 @@ stat_directory_child(const Directory *parent, const char *name,
if (!StatFile(path_fs, *st)) {
int error = errno;
const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s",
path_utf8.c_str(), g_strerror(error));
FormatErrno(update_domain, error,
"Failed to stat %s", path_utf8.c_str());
return -1;
}
......
......@@ -19,14 +19,15 @@
#include "config.h" /* must be first for large file support */
#include "UpdateRemove.hxx"
#include "UpdateDomain.hxx"
#include "Playlist.hxx"
#include "GlobalEvents.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "Song.hxx"
#include "Main.hxx"
#include "Instance.hxx"
#include "Log.hxx"
#ifdef ENABLE_SQLITE
#include "StickerDatabase.hxx"
......@@ -54,7 +55,7 @@ song_remove_event(void)
assert(removed_song != NULL);
uri = removed_song->GetURI();
g_message("removing %s", uri);
FormatInfo(update_domain, "removing %s", uri);
g_free(uri);
#ifdef ENABLE_SQLITE
......
......@@ -23,13 +23,13 @@
#include "UpdateIO.hxx"
#include "UpdateDatabase.hxx"
#include "UpdateContainer.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "DecoderPlugin.hxx"
#include "DecoderList.hxx"
#include <glib.h>
#include "Log.hxx"
#include <unistd.h>
......@@ -43,8 +43,9 @@ update_song_file2(Directory *directory,
db_unlock();
if (!directory_child_access(directory, name, R_OK)) {
g_warning("no read permissions on %s/%s",
directory->GetPath(), name);
FormatError(update_domain,
"no read permissions on %s/%s",
directory->GetPath(), name);
if (song != NULL) {
db_lock();
delete_song(directory, song);
......@@ -67,11 +68,13 @@ update_song_file2(Directory *directory,
}
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);
if (song == NULL) {
g_debug("ignoring unrecognized file %s/%s",
directory->GetPath(), name);
FormatDebug(update_domain,
"ignoring unrecognized file %s/%s",
directory->GetPath(), name);
return;
}
......@@ -80,14 +83,15 @@ update_song_file2(Directory *directory,
db_unlock();
modified = true;
g_message("added %s/%s",
directory->GetPath(), name);
FormatInfo(update_domain, "added %s/%s",
directory->GetPath(), name);
} else if (st->st_mtime != song->mtime || walk_discard) {
g_message("updating %s/%s",
directory->GetPath(), name);
FormatInfo(update_domain, "updating %s/%s",
directory->GetPath(), name);
if (!song->UpdateFile()) {
g_debug("deleting unrecognized file %s/%s",
directory->GetPath(), name);
FormatDebug(update_domain,
"deleting unrecognized file %s/%s",
directory->GetPath(), name);
db_lock();
delete_song(directory, song);
db_unlock();
......
......@@ -23,6 +23,7 @@
#include "UpdateDatabase.hxx"
#include "UpdateSong.hxx"
#include "UpdateArchive.hxx"
#include "UpdateDomain.hxx"
#include "DatabaseLock.hxx"
#include "DatabaseSimple.hxx"
#include "Directory.hxx"
......@@ -37,6 +38,7 @@
#include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx"
#include "util/UriUtil.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -49,9 +51,6 @@
#include <stdlib.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "update"
bool walk_discard;
bool modified;
......@@ -185,7 +184,7 @@ find_inode_ancestor(Directory *parent, ino_t inode, dev_t device)
return -1;
if (parent->inode == inode && parent->device == device) {
g_debug("recursive directory found");
LogDebug(update_domain, "recursive directory found");
return 1;
}
......@@ -257,7 +256,8 @@ update_directory_child(Directory *directory,
db_unlock();
}
} 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)
if (reader.HasFailed()) {
int error = errno;
const auto path_utf8 = path_fs.ToUTF8();
g_warning("Failed to open directory %s: %s",
path_utf8.c_str(), g_strerror(error));
FormatErrno(update_domain, error,
"Failed to open directory %s",
path_utf8.c_str());
return false;
}
......
......@@ -22,17 +22,18 @@
#include "MixerAll.hxx"
#include "Idle.hxx"
#include "GlobalEvents.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "volume"
#define SW_VOLUME_STATE "sw_volume: "
static constexpr Domain volume_domain("volume");
static unsigned volume_software_set = 100;
/** the cached hardware mixer value; invalid if negative */
......@@ -122,7 +123,8 @@ read_sw_volume_state(const char *line)
if (*end == 0 && sv >= 0 && sv <= 100)
software_volume_change(sv);
else
g_warning("Can't parse software volume: %s\n", line);
FormatWarning(volume_domain,
"Can't parse software volume: %s", line);
return true;
}
......
......@@ -23,6 +23,8 @@
#include "Listen.hxx"
#include "event/Loop.hxx"
#include "system/FatalError.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -36,8 +38,7 @@
#include <avahi-glib/glib-watch.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "avahi"
static constexpr Domain avahi_domain("avahi");
static char *avahiName;
static int avahiRunning;
......@@ -58,13 +59,15 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
char *n;
assert(g);
g_debug("Service group changed to state %d", state);
FormatDebug(avahi_domain,
"Service group changed to state %d", state);
switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED:
/* The entry group has been established successfully */
g_message("Service '%s' successfully established.",
avahiName);
FormatInfo(avahi_domain,
"Service '%s' successfully established.",
avahiName);
break;
case AVAHI_ENTRY_GROUP_COLLISION:
......@@ -73,43 +76,48 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
avahi_free(avahiName);
avahiName = n;
g_message("Service name collision, renaming service to '%s'",
avahiName);
FormatInfo(avahi_domain,
"Service name collision, renaming service to '%s'",
avahiName);
/* And recreate the services */
avahiRegisterService(avahi_entry_group_get_client(g));
break;
case AVAHI_ENTRY_GROUP_FAILURE:
g_warning("Entry group failure: %s",
avahi_strerror(avahi_client_errno
(avahi_entry_group_get_client(g))));
FormatError(avahi_domain,
"Entry group failure: %s",
avahi_strerror(avahi_client_errno
(avahi_entry_group_get_client(g))));
/* Some kind of failure happened while we were registering our services */
avahiRunning = 0;
break;
case AVAHI_ENTRY_GROUP_UNCOMMITED:
g_debug("Service group is UNCOMMITED");
LogDebug(avahi_domain, "Service group is UNCOMMITED");
break;
case AVAHI_ENTRY_GROUP_REGISTERING:
g_debug("Service group is REGISTERING");
LogDebug(avahi_domain, "Service group is REGISTERING");
}
}
/* Registers a new service with avahi */
static void avahiRegisterService(AvahiClient * c)
{
FormatDebug(avahi_domain, "Registering service %s/%s",
SERVICE_TYPE, avahiName);
int ret;
assert(c);
g_debug("Registering service %s/%s", SERVICE_TYPE, avahiName);
/* If this is the first time we're called,
* let's create a new entry group */
if (!avahiGroup) {
avahiGroup = avahi_entry_group_new(c, avahiGroupCallback, NULL);
if (!avahiGroup) {
g_warning("Failed to create avahi EntryGroup: %s",
avahi_strerror(avahi_client_errno(c)));
FormatError(avahi_domain,
"Failed to create avahi EntryGroup: %s",
avahi_strerror(avahi_client_errno(c)));
goto fail;
}
}
......@@ -124,16 +132,16 @@ static void avahiRegisterService(AvahiClient * c)
avahiName, SERVICE_TYPE, NULL,
NULL, listen_port, NULL);
if (ret < 0) {
g_warning("Failed to add service %s: %s", SERVICE_TYPE,
avahi_strerror(ret));
FormatError(avahi_domain, "Failed to add service %s: %s",
SERVICE_TYPE, avahi_strerror(ret));
goto fail;
}
/* Tell the server to register the service group */
ret = avahi_entry_group_commit(avahiGroup);
if (ret < 0) {
g_warning("Failed to commit service group: %s",
avahi_strerror(ret));
FormatError(avahi_domain, "Failed to commit service group: %s",
avahi_strerror(ret));
goto fail;
}
return;
......@@ -150,11 +158,11 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
assert(c);
/* 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) {
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
* name on the network, so it's time to create our services */
......@@ -165,7 +173,8 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
case AVAHI_CLIENT_FAILURE:
reason = avahi_client_errno(c);
if (reason == AVAHI_ERR_DISCONNECTED) {
g_message("Client Disconnected, will reconnect shortly");
LogInfo(avahi_domain,
"Client Disconnected, will reconnect shortly");
if (avahiGroup) {
avahi_entry_group_free(avahiGroup);
avahiGroup = NULL;
......@@ -178,51 +187,57 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
avahiClientCallback, NULL,
&reason);
if (!avahiClient) {
g_warning("Could not reconnect: %s",
avahi_strerror(reason));
FormatWarning(avahi_domain,
"Could not reconnect: %s",
avahi_strerror(reason));
avahiRunning = 0;
}
} else {
g_warning("Client failure: %s (terminal)",
avahi_strerror(reason));
FormatWarning(avahi_domain,
"Client failure: %s (terminal)",
avahi_strerror(reason));
avahiRunning = 0;
}
break;
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
* in AVAHI_SERVER_RUNNING state we will register them
* again with the new host name. */
if (avahiGroup) {
g_debug("Resetting group");
LogDebug(avahi_domain, "Resetting group");
avahi_entry_group_reset(avahiGroup);
}
break;
case AVAHI_CLIENT_S_REGISTERING:
g_debug("Client is REGISTERING");
LogDebug(avahi_domain, "Client is REGISTERING");
/* The server records are now being established. This
* might be caused by a host name change. We need to wait
* for our own records to register until the host name is
* properly esatblished. */
if (avahiGroup) {
g_debug("Resetting group");
LogDebug(avahi_domain, "Resetting group");
avahi_entry_group_reset(avahiGroup);
}
break;
case AVAHI_CLIENT_CONNECTING:
g_debug("Client is CONNECTING");
LogDebug(avahi_domain, "Client is CONNECTING");
break;
}
}
void
AvahiInit(EventLoop &loop, const char *serviceName)
{
int error;
g_debug("Initializing interface");
LogDebug(avahi_domain, "Initializing interface");
if (!avahi_is_valid_service_name(serviceName))
FormatFatalError("Invalid zeroconf_name \"%s\"", serviceName);
......@@ -241,12 +256,13 @@ AvahiInit(EventLoop &loop, const char *serviceName)
avahi_poll = avahi_glib_poll_get(avahi_glib_poll);
#endif
int error;
avahiClient = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL,
avahiClientCallback, NULL, &error);
if (!avahiClient) {
g_warning("Failed to create client: %s",
avahi_strerror(error));
FormatError(avahi_domain, "Failed to create client: %s",
avahi_strerror(error));
AvahiDeinit();
}
}
......@@ -254,7 +270,7 @@ AvahiInit(EventLoop &loop, const char *serviceName)
void
AvahiDeinit(void)
{
g_debug("Shutting down interface");
LogDebug(avahi_domain, "Shutting down interface");
if (avahiGroup) {
avahi_entry_group_free(avahiGroup);
......
......@@ -22,14 +22,15 @@
#include "ZeroconfInternal.hxx"
#include "Listen.hxx"
#include "event/SocketMonitor.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "gcc.h"
#include <glib.h>
#include <dns_sd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "bonjour"
static constexpr Domain bonjour_domain("bonjour");
class BonjourMonitor final : public SocketMonitor {
DNSServiceRef service_ref;
......@@ -64,11 +65,14 @@ dnsRegisterCallback(gcc_unused DNSServiceRef sdRef,
gcc_unused void *context)
{
if (errorCode != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service.");
LogError(bonjour_domain,
"Failed to register zeroconf service");
bonjour_monitor->Cancel();
} 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)
NULL);
if (error != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service.");
LogError(bonjour_domain,
"Failed to register zeroconf service");
if (dnsReference) {
DNSServiceRefDeallocate(dnsReference);
......
......@@ -24,9 +24,11 @@
#include "ConfigGlobal.hxx"
#include "ConfigOption.hxx"
#include "Listen.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "gcc.h"
#include <glib.h>
static constexpr Domain zeroconf_domain("zeroconf");
/* The default service name to publish
* (overridden by 'zeroconf_name' config parameter)
......@@ -48,7 +50,8 @@ ZeroconfInit(gcc_unused EventLoop &loop)
return;
if (listen_port <= 0) {
g_warning("No global port, disabling zeroconf");
LogInfo(zeroconf_domain,
"No global port, disabling zeroconf");
zeroconfEnabled = false;
return;
}
......
......@@ -31,6 +31,7 @@
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -169,7 +170,7 @@ SimpleDatabase::Open(Error &error)
if (!Load(error)) {
root->Free();
g_warning("Failed to load database: %s", error.GetMessage());
LogError(error);
error.Clear();
if (!Check(error))
......@@ -284,15 +285,15 @@ SimpleDatabase::Save(Error &error)
{
db_lock();
g_debug("removing empty directories from DB");
LogDebug(simple_db_domain, "removing empty directories from DB");
root->PruneEmpty();
g_debug("sorting DB");
LogDebug(simple_db_domain, "sorting DB");
root->Sort();
db_unlock();
g_debug("writing DB");
LogDebug(simple_db_domain, "writing DB");
FILE *fp = FOpen(path, FOpenMode::WriteText);
if (!fp) {
......
......@@ -23,6 +23,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <adplug/adplug.h>
#include <adplug/emuopl.h>
......@@ -31,9 +32,6 @@
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "adplug"
static unsigned sample_rate;
static bool
......@@ -43,7 +41,7 @@ adplug_init(const config_param &param)
sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return false;
}
......
......@@ -24,19 +24,19 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <audiofile.h>
#include <af_vfs.h>
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "audiofile"
#include <assert.h>
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
static constexpr Domain audiofile_domain("audiofile");
static int audiofile_get_duration(const char *file)
{
int total_time;
......@@ -59,7 +59,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
Error error;
size_t nbytes = is->LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) {
g_warning("%s", error.GetMessage());
LogError(error);
return -1;
}
......@@ -143,8 +143,9 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
if (!audio_valid_sample_format(audiofile_bits_to_sample_format(bits))) {
g_debug("input file has %d bit samples, converting to 16",
bits);
FormatDebug(audiofile_domain,
"input file has %d bit samples, converting to 16",
bits);
bits = 16;
}
......@@ -168,7 +169,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
char chunk[CHUNK_SIZE];
if (!is->IsSeekable()) {
g_warning("not seekable");
LogWarning(audiofile_domain, "not seekable");
return;
}
......@@ -176,7 +177,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
af_fp = afOpenVirtualFile(vf, "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) {
g_warning("failed to input stream\n");
LogWarning(audiofile_domain, "failed to input stream");
return;
}
......@@ -186,7 +187,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
audiofile_setup_sample_format(af_fp),
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
error)) {
g_warning("%s", error.GetMessage());
LogError(error);
afCloseFile(af_fp);
return;
}
......@@ -232,8 +233,9 @@ audiofile_scan_file(const char *file,
int total_time = audiofile_get_duration(file);
if (total_time < 0) {
g_debug("Failed to get total song time from: %s\n",
file);
FormatWarning(audiofile_domain,
"Failed to get total song time from: %s",
file);
return false;
}
......
......@@ -35,13 +35,11 @@
#include "util/Error.hxx"
#include "tag/TagHandler.hxx"
#include "DsdLib.hxx"
#include "Log.hxx"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "dsdiff"
struct DsdiffHeader {
struct dsdlib_id id;
uint32_t size_high, size_low;
......@@ -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,
SampleFormat::DSD,
metadata.channels, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
......
......@@ -36,13 +36,11 @@
#include "util/Error.hxx"
#include "DsdLib.hxx"
#include "tag/TagHandler.hxx"
#include "Log.hxx"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "dsf"
struct DsfMetaData {
unsigned sample_rate, channels;
bool bitreverse;
......@@ -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,
SampleFormat::DSD,
metadata.channels, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
/* Calculate song time from DSD chunk size and sample frequency */
......
......@@ -26,18 +26,14 @@
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <neaacdec.h>
#include <glib.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "faad"
#define AAC_MAX_CHANNELS 6
static const unsigned adts_sample_rates[] =
......@@ -395,7 +391,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
Error error;
ret = faad_decoder_init(decoder, buffer, audio_format, error);
if (!ret) {
g_warning("%s", error.GetMessage());
LogError(error);
NeAACDecClose(decoder);
return;
}
......@@ -424,21 +420,24 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
decoded = faad_decoder_decode(decoder, buffer, &frame_info);
if (frame_info.error > 0) {
g_warning("error decoding AAC stream: %s\n",
NeAACDecGetErrorMessage(frame_info.error));
FormatWarning(faad_decoder_domain,
"error decoding AAC stream: %s",
NeAACDecGetErrorMessage(frame_info.error));
break;
}
if (frame_info.channels != audio_format.channels) {
g_warning("channel count changed from %u to %u",
audio_format.channels, frame_info.channels);
FormatInfo(faad_decoder_domain,
"channel count changed from %u to %u",
audio_format.channels, frame_info.channels);
break;
}
if (frame_info.samplerate != audio_format.sample_rate) {
g_warning("sample rate changed from %u to %lu",
audio_format.sample_rate,
(unsigned long)frame_info.samplerate);
FormatInfo(faad_decoder_domain,
"sample rate changed from %u to %lu",
audio_format.sample_rate,
(unsigned long)frame_info.samplerate);
break;
}
......
......@@ -28,6 +28,8 @@
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "LogV.hxx"
#include <glib.h>
......@@ -50,27 +52,26 @@ extern "C" {
#include <libavutil/dict.h>
}
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
static constexpr Domain ffmpeg_domain("ffmpeg");
/* suppress the ffmpeg compatibility macro */
#ifdef SampleFormat
#undef SampleFormat
#endif
static GLogLevelFlags
level_ffmpeg_to_glib(int level)
static LogLevel
import_ffmpeg_level(int level)
{
if (level <= AV_LOG_FATAL)
return G_LOG_LEVEL_CRITICAL;
return LogLevel::ERROR;
if (level <= AV_LOG_ERROR)
return G_LOG_LEVEL_WARNING;
if (level <= AV_LOG_WARNING)
return LogLevel::WARNING;
if (level <= AV_LOG_INFO)
return G_LOG_LEVEL_MESSAGE;
return LogLevel::INFO;
return G_LOG_LEVEL_DEBUG;
return LogLevel::DEBUG;
}
static void
......@@ -83,8 +84,9 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level,
cls = *(const AVClass *const*)ptr;
if (cls != NULL) {
char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL);
g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl);
char *domain = g_strconcat(ffmpeg_domain.GetName(), "/", cls->item_name(ptr), NULL);
const Domain d(domain);
LogFormatV(d, import_ffmpeg_level(level), fmt, vl);
g_free(domain);
}
}
......@@ -287,7 +289,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
if (len < 0) {
/* if error, we skip the frame */
g_message("decoding failed, frame skipped\n");
LogInfo(ffmpeg_domain,
"decoding failed, frame skipped");
break;
}
......@@ -328,11 +331,13 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
sample_fmt);
if (name != NULL)
g_warning("Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt);
FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt);
else
g_warning("Unsupported libavcodec SampleFormat value: %d",
sample_fmt);
FormatError(ffmpeg_domain,
"Unsupported libavcodec SampleFormat value: %d",
sample_fmt);
return SampleFormat::UNDEFINED;
}
......@@ -377,12 +382,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (input_format == NULL)
return;
g_debug("detected input format '%s' (%s)",
input_format->name, input_format->long_name);
FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
input_format->name, input_format->long_name);
AvioStream stream(decoder, input);
if (!stream.Open()) {
g_warning("Failed to open stream");
LogError(ffmpeg_domain, "Failed to open stream");
return;
}
......@@ -391,21 +396,21 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (mpd_ffmpeg_open_input(&format_context, stream.io,
input->uri.c_str(),
input_format) != 0) {
g_warning("Open failed\n");
LogError(ffmpeg_domain, "Open failed");
return;
}
const int find_result =
avformat_find_stream_info(format_context, NULL);
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);
return;
}
int audio_stream = ffmpeg_find_audio_stream(format_context);
if (audio_stream == -1) {
g_warning("No audio stream inside\n");
LogError(ffmpeg_domain, "No audio stream inside");
avformat_close_input(&format_context);
return;
}
......@@ -414,12 +419,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVCodecContext *codec_context = av_stream->codec;
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);
if (!codec) {
g_warning("Unsupported audio codec\n");
LogError(ffmpeg_domain, "Unsupported audio codec");
avformat_close_input(&format_context);
return;
}
......@@ -435,7 +441,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
codec_context->sample_rate,
sample_format,
codec_context->channels, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
avformat_close_input(&format_context);
return;
}
......@@ -447,7 +453,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
const int open_result = avcodec_open2(codec_context, codec, NULL);
if (open_result < 0) {
g_warning("Could not open codec\n");
LogError(ffmpeg_domain, "Could not open codec");
avformat_close_input(&format_context);
return;
}
......@@ -461,7 +467,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVFrame *frame = avcodec_alloc_frame();
if (!frame) {
g_warning("Could not allocate frame\n");
LogError(ffmpeg_domain, "Could not allocate frame");
avformat_close_input(&format_context);
return;
}
......
......@@ -25,9 +25,6 @@
#include "tag/TagTable.hxx"
#include "tag/TagHandler.hxx"
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
static const struct tag_table ffmpeg_tags[] = {
{ "year", TAG_DATE },
{ "author-sort", TAG_ARTIST_SORT },
......
......@@ -27,8 +27,8 @@
#include "FlacPcm.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h>
......@@ -74,7 +74,7 @@ flac_got_stream_info(struct flac_data *data,
stream_info->sample_rate,
flac_sample_format(stream_info->bits_per_sample),
stream_info->channels, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
data->unsupported = true;
return;
}
......@@ -136,7 +136,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
header->sample_rate,
flac_sample_format(header->bits_per_sample),
header->channels, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
data->unsupported = true;
return false;
}
......
......@@ -31,9 +31,6 @@
#include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "flac"
struct flac_data : public FlacInput {
PcmBuffer buffer;
......
......@@ -19,10 +19,12 @@
#include "config.h" /* must be first for large file support */
#include "FlacDecoderPlugin.h"
#include "FlacDomain.hxx"
#include "FlacCommon.hxx"
#include "FlacMetadata.hxx"
#include "OggCodec.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -54,7 +56,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
break;
}
g_warning("%s\n", FLAC__StreamDecoderStateString[state]);
LogError(flac_domain, FLAC__StreamDecoderStateString[state]);
}
static void flacMetadata(gcc_unused const FLAC__StreamDecoder * dec,
......@@ -90,8 +92,9 @@ flac_scan_file(const char *file,
{
FlacMetadataChain chain;
if (!chain.Read(file)) {
g_debug("Failed to read FLAC tags: %s",
chain.GetStatusString());
FormatDebug(flac_domain,
"Failed to read FLAC tags: %s",
chain.GetStatusString());
return false;
}
......@@ -105,8 +108,9 @@ flac_scan_stream(struct input_stream *is,
{
FlacMetadataChain chain;
if (!chain.Read(is)) {
g_debug("Failed to read FLAC tags: %s",
chain.GetStatusString());
FormatDebug(flac_domain,
"Failed to read FLAC tags: %s",
chain.GetStatusString());
return false;
}
......@@ -122,12 +126,14 @@ flac_decoder_new(void)
{
FLAC__StreamDecoder *sd = FLAC__stream_decoder_new();
if (sd == nullptr) {
g_warning("FLAC__stream_decoder_new() failed");
LogError(flac_domain,
"FLAC__stream_decoder_new() failed");
return nullptr;
}
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;
}
......@@ -139,7 +145,7 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
data->total_frames = duration;
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
g_warning("problem reading metadata");
LogWarning(flac_domain, "problem reading metadata");
return false;
}
......@@ -265,7 +271,8 @@ flac_decode_internal(struct decoder * decoder,
stream_init(flac_dec, &data, is_ogg);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(flac_dec);
g_warning("%s", FLAC__StreamDecoderInitStatusString[status]);
LogWarning(flac_domain,
FLAC__StreamDecoderInitStatusString[status]);
return;
}
......@@ -299,8 +306,9 @@ oggflac_scan_file(const char *file,
{
FlacMetadataChain chain;
if (!chain.ReadOgg(file)) {
g_debug("Failed to read OggFLAC tags: %s",
chain.GetStatusString());
FormatDebug(flac_domain,
"Failed to read OggFLAC tags: %s",
chain.GetStatusString());
return false;
}
......@@ -314,8 +322,9 @@ oggflac_scan_stream(struct input_stream *is,
{
FlacMetadataChain chain;
if (!chain.ReadOgg(is)) {
g_debug("Failed to read OggFLAC tags: %s",
chain.GetStatusString());
FormatDebug(flac_domain,
"Failed to read OggFLAC tags: %s",
chain.GetStatusString());
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