summaryrefslogtreecommitdiffstats
path: root/src/daemon
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/daemon
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/daemon')
-rw-r--r--src/daemon/cmdline.c5
-rw-r--r--src/daemon/daemon-conf.c21
2 files changed, 24 insertions, 2 deletions
diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c
index f6cdcdc8..4854affc 100644
--- a/src/daemon/cmdline.c
+++ b/src/daemon/cmdline.c
@@ -145,7 +145,8 @@ void pa_cmdline_help(const char *argv0) {
" this time passed\n"
" --log-level[=LEVEL] Increase or set verbosity level\n"
" -v Increase the verbosity level\n"
- " --log-target={auto,syslog,stderr} Specify the log target\n"
+ " --log-target={auto,syslog,stderr,file:PATH}\n"
+ " Specify the log target\n"
" --log-meta[=BOOL] Include code location in log messages\n"
" --log-time[=BOOL] Include timestamps in log messages\n"
" --log-backtrace=FRAMES Include a backtrace in log messages\n"
@@ -318,7 +319,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
case ARG_LOG_TARGET:
if (pa_daemon_conf_set_log_target(conf, optarg) < 0) {
- pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto'."));
+ pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto' or a valid file name 'file:<path>'."));
goto fail;
}
break;
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index e38e67ad..ce93dbc6 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#ifdef HAVE_SCHED_H
#include <sched.h>
@@ -166,6 +167,9 @@ pa_daemon_conf* pa_daemon_conf_new(void) {
void pa_daemon_conf_free(pa_daemon_conf *c) {
pa_assert(c);
+
+ pa_log_set_fd(-1);
+
pa_xfree(c->script_commands);
pa_xfree(c->dl_search_path);
pa_xfree(c->default_script_file);
@@ -211,6 +215,23 @@ int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
c->log_level = PA_LOG_WARN;
else if (pa_startswith(string, "err"))
c->log_level = PA_LOG_ERROR;
+ else if (pa_startswith(string, "file:")) {
+ char file_path[512];
+ int log_fd;
+
+ pa_strlcpy(file_path, string + 5, sizeof(file_path));
+
+ /* Open target file with user rights */
+ if ((log_fd = open(file_path, O_RDWR|O_TRUNC|O_CREAT, S_IRWXU)) >= 0) {
+ c->auto_log_target = 0;
+ c->log_target = PA_LOG_FD;
+ pa_log_set_fd(log_fd);
+ }
+ else {
+ printf("Failed to open target file %s, error : %s\n", file_path, pa_cstrerror(errno));
+ return -1;
+ }
+ }
else
return -1;