Log: new logging library API

Prepare to migrate away from GLib.  Currently, we're still using GLib
as a backend.
This commit is contained in:
Max Kellermann
2013-09-27 22:31:24 +02:00
parent c53492a76a
commit 060814daa8
162 changed files with 1992 additions and 1280 deletions

View File

@@ -25,15 +25,13 @@
#include "util/Manual.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <alsa/asoundlib.h>
#include <string>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "alsa"
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
@@ -216,8 +214,9 @@ alsa_test_default_device(void)
int ret = snd_pcm_open(&handle, default_device,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (ret) {
g_message("Error opening default ALSA device: %s\n",
snd_strerror(-ret));
FormatError(alsa_output_domain,
"Error opening default ALSA device: %s",
snd_strerror(-ret));
return false;
} else
snd_pcm_close(handle);
@@ -413,9 +412,11 @@ configure_hw:
err = snd_pcm_hw_params_set_access(ad->pcm, hwparams,
SND_PCM_ACCESS_MMAP_INTERLEAVED);
if (err < 0) {
g_warning("Cannot set mmap'ed mode on ALSA device \"%s\": %s\n",
alsa_device(ad), snd_strerror(-err));
g_warning("Falling back to direct write mode\n");
FormatWarning(alsa_output_domain,
"Cannot set mmap'ed mode on ALSA device \"%s\": %s",
alsa_device(ad), snd_strerror(-err));
LogWarning(alsa_output_domain,
"Falling back to direct write mode");
ad->use_mmap = false;
} else
ad->writei = snd_pcm_mmap_writei;
@@ -443,8 +444,9 @@ configure_hw:
snd_pcm_format_t format;
if (snd_pcm_hw_params_get_format(hwparams, &format) == 0)
g_debug("format=%s (%s)", snd_pcm_format_name(format),
snd_pcm_format_description(format));
FormatDebug(alsa_output_domain,
"format=%s (%s)", snd_pcm_format_name(format),
snd_pcm_format_description(format));
err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams,
&channels);
@@ -473,9 +475,9 @@ configure_hw:
unsigned buffer_time_min, buffer_time_max;
snd_pcm_hw_params_get_buffer_time_min(hwparams, &buffer_time_min, 0);
snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time_max, 0);
g_debug("buffer: size=%u..%u time=%u..%u",
(unsigned)buffer_size_min, (unsigned)buffer_size_max,
buffer_time_min, buffer_time_max);
FormatDebug(alsa_output_domain, "buffer: size=%u..%u time=%u..%u",
(unsigned)buffer_size_min, (unsigned)buffer_size_max,
buffer_time_min, buffer_time_max);
snd_pcm_uframes_t period_size_min, period_size_max;
snd_pcm_hw_params_get_period_size_min(hwparams, &period_size_min, 0);
@@ -483,9 +485,9 @@ configure_hw:
unsigned period_time_min, period_time_max;
snd_pcm_hw_params_get_period_time_min(hwparams, &period_time_min, 0);
snd_pcm_hw_params_get_period_time_max(hwparams, &period_time_max, 0);
g_debug("period: size=%u..%u time=%u..%u",
(unsigned)period_size_min, (unsigned)period_size_max,
period_time_min, period_time_max);
FormatDebug(alsa_output_domain, "period: size=%u..%u time=%u..%u",
(unsigned)period_size_min, (unsigned)period_size_max,
period_time_min, period_time_max);
if (ad->buffer_time > 0) {
buffer_time = ad->buffer_time;
@@ -504,8 +506,9 @@ configure_hw:
if (period_time_ro == 0 && buffer_time >= 10000) {
period_time_ro = period_time = buffer_time / 4;
g_debug("default period_time = buffer_time/4 = %u/4 = %u",
buffer_time, period_time);
FormatDebug(alsa_output_domain,
"default period_time = buffer_time/4 = %u/4 = %u",
buffer_time, period_time);
}
if (period_time_ro > 0) {
@@ -525,7 +528,8 @@ configure_hw:
} else if (err < 0)
goto error;
if (retry != MPD_ALSA_RETRY_NR)
g_debug("ALSA period_time set to %d\n", period_time);
FormatDebug(alsa_output_domain,
"ALSA period_time set to %d", period_time);
snd_pcm_uframes_t alsa_buffer_size;
cmd = "snd_pcm_hw_params_get_buffer_size";
@@ -567,8 +571,8 @@ configure_hw:
if (err < 0)
goto error;
g_debug("buffer_size=%u period_size=%u",
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u",
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
if (alsa_period_size == 0)
/* this works around a SIGFPE bug that occurred when
@@ -673,8 +677,9 @@ alsa_open(struct audio_output *ao, AudioFormat &audio_format, Error &error)
return false;
}
g_debug("opened %s type=%s", snd_pcm_name(ad->pcm),
snd_pcm_type_name(snd_pcm_type(ad->pcm)));
FormatDebug(alsa_output_domain, "opened %s type=%s",
snd_pcm_name(ad->pcm),
snd_pcm_type_name(snd_pcm_type(ad->pcm)));
if (!alsa_setup_or_dsd(ad, audio_format, error)) {
snd_pcm_close(ad->pcm);
@@ -700,9 +705,12 @@ static int
alsa_recover(AlsaOutput *ad, int err)
{
if (err == -EPIPE) {
g_debug("Underrun on ALSA device \"%s\"\n", alsa_device(ad));
FormatDebug(alsa_output_domain,
"Underrun on ALSA device \"%s\"", alsa_device(ad));
} else if (err == -ESTRPIPE) {
g_debug("ALSA device \"%s\" was suspended\n", alsa_device(ad));
FormatDebug(alsa_output_domain,
"ALSA device \"%s\" was suspended",
alsa_device(ad));
}
switch (snd_pcm_state(ad->pcm)) {

View File

@@ -22,15 +22,13 @@
#include "OutputAPI.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <ao/ao.h>
#include <glib.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ao"
/* An ao_sample_format, with all fields set to zero: */
static ao_sample_format OUR_AO_FORMAT_INITIALIZER;
@@ -125,8 +123,8 @@ AoOutput::Configure(const config_param &param, Error &error)
return false;
}
g_debug("using ao driver \"%s\" for \"%s\"\n", ai->short_name,
param.GetBlockValue("name", nullptr));
FormatDebug(ao_output_domain, "using ao driver \"%s\" for \"%s\"\n",
ai->short_name, param.GetBlockValue("name", nullptr));
value = param.GetBlockValue("options", nullptr);
if (value != nullptr) {

View File

@@ -27,19 +27,15 @@
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "open.h"
#include <glib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "fifo"
#define FIFO_BUFFER_SIZE 65536 /* pipe capacity on Linux >= 2.6.11 */
struct FifoOutput {
@@ -78,11 +74,13 @@ static constexpr Domain fifo_output_domain("fifo_output");
inline void
FifoOutput::Delete()
{
g_debug("Removing FIFO \"%s\"", path_utf8.c_str());
FormatDebug(fifo_output_domain,
"Removing FIFO \"%s\"", path_utf8.c_str());
if (!RemoveFile(path)) {
g_warning("Could not remove FIFO \"%s\": %s",
path_utf8.c_str(), g_strerror(errno));
FormatErrno(fifo_output_domain,
"Could not remove FIFO \"%s\"",
path_utf8.c_str());
return;
}
@@ -249,8 +247,9 @@ fifo_output_cancel(struct audio_output *ao)
bytes = read(fd->input, buf, FIFO_BUFFER_SIZE);
if (bytes < 0 && errno != EAGAIN) {
g_warning("Flush of FIFO \"%s\" failed: %s",
fd->path_utf8.c_str(), g_strerror(errno));
FormatErrno(fifo_output_domain,
"Flush of FIFO \"%s\" failed",
fd->path_utf8.c_str());
}
}

View File

@@ -24,13 +24,11 @@
#include "Page.hxx"
#include "IcyMetaDataServer.hxx"
#include "system/SocketError.hxx"
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "httpd_output"
HttpdClient::~HttpdClient()
{
if (state == RESPONSE) {
@@ -80,7 +78,8 @@ HttpdClient::HandleLine(const char *line)
if (state == REQUEST) {
if (strncmp(line, "GET /", 5) != 0) {
/* only GET is supported */
g_warning("malformed request line from client");
LogWarning(httpd_output_domain,
"malformed request line from client");
return false;
}
@@ -171,7 +170,9 @@ HttpdClient::SendResponse()
ssize_t nbytes = SocketMonitor::Write(buffer, strlen(buffer));
if (gcc_unlikely(nbytes < 0)) {
const SocketErrorMessage msg;
g_warning("failed to write to client: %s", (const char *)msg);
FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg);
Close();
return false;
}
@@ -278,8 +279,9 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e);
g_warning("failed to write to client: %s",
(const char *)msg);
FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg);
}
Close();
@@ -304,8 +306,9 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e);
g_warning("failed to write to client: %s",
(const char *)msg);
FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg);
}
Close();
@@ -326,8 +329,9 @@ HttpdClient::TryWrite()
if (!IsSocketErrorClosed(e)) {
SocketErrorMessage msg(e);
g_warning("failed to write to client: %s",
(const char *)msg);
FormatWarning(httpd_output_domain,
"failed to write to client: %s",
(const char *)msg);
}
Close();
@@ -399,7 +403,8 @@ BufferedSocket::InputResult
HttpdClient::OnSocketInput(const void *data, size_t length)
{
if (state == RESPONSE) {
g_warning("unexpected input from client");
LogWarning(httpd_output_domain,
"unexpected input from client");
LockClose();
return InputResult::CLOSED;
}
@@ -433,7 +438,7 @@ HttpdClient::OnSocketInput(const void *data, size_t length)
void
HttpdClient::OnSocketError(Error &&error)
{
g_warning("error on HTTP client: %s", error.GetMessage());
LogError(error);
}
void

View File

@@ -205,4 +205,6 @@ private:
size_t address_length, int uid) override;
};
extern const class Domain httpd_output_domain;
#endif

View File

@@ -31,6 +31,7 @@
#include "Main.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h>
@@ -44,10 +45,7 @@
#include <tcpd.h>
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "httpd_output"
static constexpr Domain httpd_output_domain("httpd_output");
const Domain httpd_output_domain("httpd_output");
inline
HttpdOutput::HttpdOutput(EventLoop &_loop)
@@ -210,8 +208,9 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address,
if (!hosts_access(&req)) {
/* tcp wrappers says no */
g_warning("libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr);
FormatWarning(httpd_output_domain,
"libwrap refused connection (libwrap=%s) from %s",
progname, hostaddr);
g_free(hostaddr);
close_socket(fd);
return;
@@ -233,7 +232,7 @@ HttpdOutput::OnAccept(int fd, const sockaddr &address,
else
close_socket(fd);
} else if (fd < 0 && errno != EINTR) {
g_warning("accept() failed: %s", g_strerror(errno));
LogErrno(httpd_output_domain, "accept() failed");
}
}
@@ -420,7 +419,8 @@ HttpdOutput::BroadcastFromEncoder()
mutex.lock();
for (auto &client : clients) {
if (client.GetQueueSize() > 256 * 1024) {
g_debug("client is too slow, flushing its queue");
FormatDebug(httpd_output_domain,
"client is too slow, flushing its queue");
client.CancelQueue();
}
}

View File

@@ -23,6 +23,7 @@
#include "ConfigError.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <assert.h>
@@ -38,9 +39,6 @@
#include <unistd.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "jack"
enum {
MAX_PORTS = 16,
};
@@ -216,14 +214,14 @@ set_audioformat(JackOutput *jd, AudioFormat &audio_format)
static void
mpd_jack_error(const char *msg)
{
g_warning("%s", msg);
LogError(jack_output_domain, msg);
}
#ifdef HAVE_JACK_SET_INFO_FUNCTION
static void
mpd_jack_info(const char *msg)
{
g_message("%s", msg);
LogInfo(jack_output_domain, msg);
}
#endif
@@ -360,8 +358,9 @@ mpd_jack_init(const config_param &param, Error &error)
/* compatibility with MPD < 0.16 */
value = param.GetBlockValue("ports", nullptr);
if (value != nullptr)
g_warning("deprecated option 'ports' in line %d",
param.line);
FormatWarning(jack_output_domain,
"deprecated option 'ports' in line %d",
param.line);
}
if (value != nullptr) {
@@ -376,10 +375,11 @@ mpd_jack_init(const config_param &param, Error &error)
if (jd->num_destination_ports > 0 &&
jd->num_destination_ports != jd->num_source_ports)
g_warning("number of source ports (%u) mismatches the "
"number of destination ports (%u) in line %d",
jd->num_source_ports, jd->num_destination_ports,
param.line);
FormatWarning(jack_output_domain,
"number of source ports (%u) mismatches the "
"number of destination ports (%u) in line %d",
jd->num_source_ports, jd->num_destination_ports,
param.line);
jd->ringbuffer_size = param.GetBlockValue("ringbuffer_size", 32768u);
@@ -500,9 +500,10 @@ mpd_jack_start(JackOutput *jd, Error &error)
num_destination_ports < MAX_PORTS &&
jports[num_destination_ports] != nullptr;
++num_destination_ports) {
g_debug("destination_port[%u] = '%s'\n",
num_destination_ports,
jports[num_destination_ports]);
FormatDebug(jack_output_domain,
"destination_port[%u] = '%s'\n",
num_destination_ports,
jports[num_destination_ports]);
destination_ports[num_destination_ports] =
jports[num_destination_ports];
}

View File

@@ -25,15 +25,13 @@
#include "util/Domain.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
#include <glib.h>
#include <CoreAudio/AudioHardware.h>
#include <AudioUnit/AudioUnit.h>
#include <CoreServices/CoreServices.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "osx"
struct OSXOutput {
struct audio_output base;
@@ -156,15 +154,17 @@ osx_output_set_device(OSXOutput *oo, Error &error)
goto done;
}
if (strcmp(oo->device_name, name) == 0) {
g_debug("found matching device: ID=%u, name=%s",
(unsigned int) deviceids[i], name);
FormatDebug(osx_output_domain,
"found matching device: ID=%u, name=%s",
(unsigned)deviceids[i], name);
break;
}
}
if (i == numdevices) {
g_warning("Found no audio device with name '%s' "
"(will use default audio device)",
oo->device_name);
FormatWarning(osx_output_domain,
"Found no audio device with name '%s' "
"(will use default audio device)",
oo->device_name);
goto done;
}
@@ -181,8 +181,10 @@ osx_output_set_device(OSXOutput *oo, Error &error)
ret = false;
goto done;
}
g_debug("set OS X audio output device ID=%u, name=%s",
(unsigned int) deviceids[i], name);
FormatDebug(osx_output_domain,
"set OS X audio output device ID=%u, name=%s",
(unsigned)deviceids[i], name);
done:
delete[] deviceids;

View File

@@ -33,9 +33,6 @@
#include <OpenAL/alc.h>
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "openal"
/* should be enough for buffer size = 2048 */
#define NUM_BUFFERS 16

View File

@@ -24,6 +24,7 @@
#include "system/fd_util.h"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
@@ -35,9 +36,6 @@
#include <unistd.h>
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "oss"
#if defined(__OpenBSD__) || defined(__NetBSD__)
# include <soundcard.h>
#else /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
@@ -142,8 +140,10 @@ oss_output_test_default_device(void)
close(fd);
return true;
}
g_warning("Error opening OSS device \"%s\": %s\n",
default_devices[i], g_strerror(errno));
FormatErrno(oss_output_domain,
"Error opening OSS device \"%s\"",
default_devices[i]);
}
return false;
@@ -177,17 +177,20 @@ oss_open_default(Error &error)
/* never reached */
break;
case OSS_STAT_DOESN_T_EXIST:
g_warning("%s not found\n", dev);
FormatWarning(oss_output_domain,
"%s not found", dev);
break;
case OSS_STAT_NOT_CHAR_DEV:
g_warning("%s is not a character device\n", dev);
FormatWarning(oss_output_domain,
"%s is not a character device", dev);
break;
case OSS_STAT_NO_PERMS:
g_warning("%s: permission denied\n", dev);
FormatWarning(oss_output_domain,
"%s: permission denied", dev);
break;
case OSS_STAT_OTHER:
g_warning("Error accessing %s: %s\n",
dev, g_strerror(err[i]));
FormatErrno(oss_output_domain, err[i],
"Error accessing %s", dev);
}
}

View File

@@ -24,6 +24,7 @@
#include "mixer/PulseMixerPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
@@ -628,8 +629,9 @@ pulse_output_close(struct audio_output *ao)
o = pa_stream_drain(po->stream,
pulse_output_stream_success_cb, po);
if (o == nullptr) {
g_warning("pa_stream_drain() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
FormatWarning(pulse_output_domain,
"pa_stream_drain() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
} else
pulse_wait_for_operation(po->mainloop, o);
}
@@ -804,8 +806,9 @@ pulse_output_cancel(struct audio_output *ao)
o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po);
if (o == nullptr) {
g_warning("pa_stream_flush() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
FormatWarning(pulse_output_domain,
"pa_stream_flush() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
pa_threaded_mainloop_unlock(po->mainloop);
return;
}
@@ -829,7 +832,7 @@ pulse_output_pause(struct audio_output *ao)
Error error;
if (!pulse_output_wait_stream(po, error)) {
pa_threaded_mainloop_unlock(po->mainloop);
g_warning("%s", error.GetMessage());
LogError(error);
return false;
}
@@ -840,7 +843,7 @@ pulse_output_pause(struct audio_output *ao)
if (!pa_stream_is_corked(po->stream) &&
!pulse_output_stream_pause(po, true, error)) {
pa_threaded_mainloop_unlock(po->mainloop);
g_warning("%s", error.GetMessage());
LogError(error);
return false;
}

View File

@@ -34,9 +34,6 @@
#include <unistd.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "recorder"
struct RecorderOutput {
struct audio_output base;

View File

@@ -25,6 +25,7 @@
#include "thread/Mutex.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
@@ -34,9 +35,6 @@
#include <roaraudio.h>
#undef new
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "roaraudio"
struct RoarOutput {
struct audio_output base;
@@ -242,7 +240,7 @@ roar_cancel_locked(RoarOutput *self)
if (roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY,
&(self->err)) < 0) {
roar_vs_close(vss, ROAR_VS_TRUE, &(self->err));
g_warning("Failed to start stream");
LogError(roar_output_domain, "Failed to start stream");
return;
}

View File

@@ -26,6 +26,7 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include <shout/shout.h>
#include <glib.h>
@@ -35,9 +36,6 @@
#include <string.h>
#include <stdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "shout"
static constexpr unsigned DEFAULT_CONN_TIMEOUT = 2;
struct ShoutOutput final {
@@ -358,8 +356,9 @@ static void close_shout_conn(ShoutOutput * sd)
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
shout_close(sd->shout_conn) != SHOUTERR_SUCCESS) {
g_warning("problem closing connection to shout server: %s\n",
shout_get_error(sd->shout_conn));
FormatWarning(shout_output_domain,
"problem closing connection to shout server: %s",
shout_get_error(sd->shout_conn));
}
}
@@ -507,7 +506,7 @@ static void my_shout_set_tag(struct audio_output *ao,
if (!encoder_pre_tag(sd->encoder, error) ||
!write_page(sd, error) ||
!encoder_tag(sd->encoder, tag, error)) {
g_warning("%s", error.GetMessage());
LogError(error);
return;
}
} else {
@@ -518,7 +517,8 @@ static void my_shout_set_tag(struct audio_output *ao,
shout_metadata_add(sd->shout_meta, "song", song);
if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shout_conn,
sd->shout_meta)) {
g_warning("error setting shout metadata\n");
LogWarning(shout_output_domain,
"error setting shout metadata");
}
}

View File

@@ -49,9 +49,6 @@ struct audio_info {
#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "solaris_output"
struct SolarisOutput {
struct audio_output base;

View File

@@ -30,9 +30,6 @@
#include <stdlib.h>
#include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "winmm_output"
struct WinmmBuffer {
PcmBuffer buffer;