summaryrefslogtreecommitdiffhomepage
path: root/src/log.c
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-11-04 00:42:05 +0100
committerMichael Adam <obnox@samba.org>2009-11-14 12:13:10 +0100
commitea2eaef173b56213fe58f42b9478164f7abdbfb7 (patch)
tree68d3abb8e22e0f1269e3547acbf9a864da476f37 /src/log.c
parentd8da7f55f7111174c49d716046d997f7b7f23f59 (diff)
extract setup of the logging subsystem into a function of its own.
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
index 57bf925..4398488 100644
--- a/src/log.c
+++ b/src/log.c
@@ -243,3 +243,40 @@ void send_stored_logs (void)
vector_delete (log_message_storage);
log_message_storage = NULL;
}
+
+/**
+ * Initialize the logging subsystem, based on the configuration.
+ * Returns 0 upon success, -1 upon failure.
+ *
+ * This function uses fprintf() instead of log_message(), since
+ * the logging is not yet set up...
+ */
+int setup_logging (void)
+{
+ int ret = -1;
+
+ /* Write to a user supplied log file if it's defined. This will
+ * override using the syslog even if syslog is defined. */
+ if (config.logf_name) {
+ if (open_log_file (config.logf_name) < 0) {
+ fprintf (stderr,
+ "%s: Could not create log file.\n", PACKAGE);
+ goto done;
+ }
+ config.syslog = FALSE; /* disable syslog */
+ } else if (config.syslog) {
+ if (config.godaemon == TRUE)
+ openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
+ else
+ openlog ("tinyproxy", LOG_PID, LOG_USER);
+ } else {
+ fprintf (stderr, "%s: Either define a logfile or "
+ "enable syslog logging.\n", PACKAGE);
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ return ret;
+}