diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-26 19:43:47 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-26 19:43:47 +0200 |
commit | e1038263368bc2a70ce59f1543e808b5b958c5cb (patch) | |
tree | 9dd4777cf0aaad6ce18dfbf1c6cc358156863207 /src/diag.c | |
parent | fd2468864b719af4cfb0266b1bb8c6b0dbd53aa0 (diff) | |
download | pies-e1038263368bc2a70ce59f1543e808b5b958c5cb.tar.gz pies-e1038263368bc2a70ce59f1543e808b5b958c5cb.tar.bz2 |
Improve diagnostic output.
* src/diag.c (diag_output): New variable.
(diag_setup): New function.
(vlogmsg): Use diag_output to decide where to
output the message. Output to both stderr and
syslog if diag_output says so.
* src/pies.c (log_to_stderr): Rename to log_to_stderr_only.
All uses changed.
(log_setup): Remove.
(main): Use diag_setup to initialize diagnostics.
* src/pies.h (log_to_stderr): Remove.
(DIAG_TO_SYSLOG, DIAG_TO_STDERR): New defines.
(diag_setup): New function.
Diffstat (limited to 'src/diag.c')
-rw-r--r-- | src/diag.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -19,6 +19,16 @@ unsigned debug_level; int source_info_option; +int diag_output = DIAG_TO_STDERR; + +void +diag_setup (int flags) +{ + if (flags) + diag_output = flags; + if (diag_output & DIAG_TO_SYSLOG) + openlog (log_tag, LOG_PID, log_facility); +} void syslog_printer (int prio, const char *fmt, va_list ap) @@ -35,12 +45,13 @@ syslog_printer (int prio, const char *fmt, va_list ap) void vlogmsg (int prio, const char *fmt, va_list ap) { - if (log_to_stderr) + if (DIAG_OUTPUT (DIAG_TO_STDERR)) { + fprintf (stderr, "%s: ", program_name); vfprintf (stderr, fmt, ap); fprintf (stderr, "\n"); } - else + if (DIAG_OUTPUT (DIAG_TO_SYSLOG)) syslog_printer (prio, fmt, ap); } |