summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/log.c
diff options
context:
space:
mode:
authorVincent Becker <vincentx.becker@intel.com>2011-03-18 11:23:46 +0100
committerColin Guthrie <cguthrie@mandriva.org>2011-03-18 12:32:51 +0000
commitf7acd4bdab7092700a9386802a0ec86d4362e58c (patch)
treef21aa3373c9816778fa7067682f766babfc7834f /src/pulsecore/log.c
parent26366664c140664f70d46772f0d1a790ec885410 (diff)
log: Add a new log target to a file descriptor
This patch enables logging of text debug messages (pa_log feature) into a file or a device driver. Example : pulseaudio --log-target=file:./mylog.txt (Minor tweaks by Colin + Arun)
Diffstat (limited to 'src/pulsecore/log.c')
-rw-r--r--src/pulsecore/log.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
index 2c0e267a..b12cbf0c 100644
--- a/src/pulsecore/log.c
+++ b/src/pulsecore/log.c
@@ -70,6 +70,7 @@ static pa_log_level_t maximum_level = PA_LOG_ERROR, maximum_level_override = PA_
static unsigned show_backtrace = 0, show_backtrace_override = 0, skip_backtrace = 0;
static pa_log_flags_t flags = 0, flags_override = 0;
static pa_bool_t no_rate_limit = FALSE;
+static int log_fd = -1;
#ifdef HAVE_SYSLOG_H
static const int level_to_syslog[] = {
@@ -128,6 +129,15 @@ void pa_log_set_flags(pa_log_flags_t _flags, pa_log_merge_t merge) {
flags = _flags;
}
+void pa_log_set_fd(int fd) {
+ if (fd >= 0)
+ log_fd = fd;
+ else if (log_fd >= 0) {
+ pa_close(log_fd);
+ log_fd = -1;
+ }
+}
+
void pa_log_set_show_backtrace(unsigned nlevels) {
show_backtrace = nlevels;
}
@@ -399,6 +409,23 @@ void pa_log_levelv_meta(
}
#endif
+ case PA_LOG_FD: {
+ if (log_fd >= 0) {
+ char metadata[256];
+
+ pa_snprintf(metadata, sizeof(metadata), "\n%c %s %s", level_to_char[level], timestamp, location);
+
+ if ((write(log_fd, metadata, strlen(metadata)) < 0) || (write(log_fd, t, strlen(t)) < 0)) {
+ saved_errno = errno;
+ pa_log_set_fd(-1);
+ fprintf(stderr, "%s\n", "Error writing logs to a file descriptor. Redirect log messages to console.");
+ fprintf(stderr, "%s %s\n", metadata, t);
+ pa_log_set_target(PA_LOG_STDERR);
+ }
+ }
+
+ break;
+ }
case PA_LOG_NULL:
default:
break;