aboutsummaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-10-26 21:48:41 +0000
committerNick Mathewson <nickm@torproject.org>2004-10-26 21:48:41 +0000
commit26f3cb865202160fe6b8ecfb20a0e41fea3a4a6a (patch)
tree4f0246453c39783f476c2b088a961d3fc0bf2da8 /src/or/config.c
parent64fc462a3a8687845c255c32941fee98a31eb3f3 (diff)
downloadtor-26f3cb865202160fe6b8ecfb20a0e41fea3a4a6a.tar
tor-26f3cb865202160fe6b8ecfb20a0e41fea3a4a6a.tar.gz
Add SysLog option to direct log messages to the system log instead of a FILE*.
svn:r2591
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/or/config.c b/src/or/config.c
index aafe4c2d0..d12b5e9db 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -292,7 +292,7 @@ config_assign(or_options_t *options, struct config_line_t *list)
config_compare(list, "SocksPort", CONFIG_TYPE_UINT, &options->SocksPort) ||
config_compare(list, "SocksBindAddress",CONFIG_TYPE_LINELIST,&options->SocksBindAddress) ||
config_compare(list, "SocksPolicy", CONFIG_TYPE_LINELIST,&options->SocksPolicy) ||
-
+ config_compare(list, "SysLog", CONFIG_TYPE_LINELIST,&options->LogOptions) ||
config_compare(list, "TrafficShaping", CONFIG_TYPE_OBSOLETE, NULL) ||
config_compare(list, "User", CONFIG_TYPE_STRING, &options->User)
@@ -964,7 +964,8 @@ add_single_log(struct config_line_t *level_opt,
} else {
levelMax = LOG_ERR;
}
- if (file_opt) {
+
+ if (file_opt && !strcasecmp(file_opt->key, "LogFile")) {
if (add_file_log(levelMin, levelMax, file_opt->value) < 0) {
log_fn(LOG_WARN, "Cannot write to LogFile '%s': %s.", file_opt->value,
strerror(errno));
@@ -972,6 +973,16 @@ add_single_log(struct config_line_t *level_opt,
}
log_fn(LOG_NOTICE, "Successfully opened LogFile '%s', redirecting output.",
file_opt->value);
+ } else if (file_opt && !strcasecmp(file_opt->key, "SysLog")) {
+#ifdef HAVE_SYSLOG_H
+ if (add_syslog_log(levelMin, levelMax) < 0) {
+ log_fn(LOG_WARN, "Cannot open system log facility");
+ return -1;
+ }
+ log_fn(LOG_NOTICE, "Successfully opened system log, redirecting output.");
+#else
+ log_fn(LOG_WARN, "Tor was compiled without system logging enabled; can't enable SysLog.");
+#endif
} else if (!isDaemon) {
add_stream_log(levelMin, levelMax, "<stdout>", stdout);
close_temp_logs();
@@ -998,7 +1009,8 @@ config_init_logs(or_options_t *options)
/* Special case for if first option is LogLevel. */
if (opt && !strcasecmp(opt->key, "LogLevel")) {
- if (opt->next && !strcasecmp(opt->next->key, "LogFile")) {
+ if (opt->next && (!strcasecmp(opt->next->key, "LogFile") ||
+ !strcasecmp(opt->next->key, "SysLog"))) {
if (add_single_log(opt, opt->next, options->RunAsDaemon) < 0)
return -1;
opt = opt->next->next;
@@ -1013,17 +1025,18 @@ config_init_logs(or_options_t *options)
while (opt) {
if (!strcasecmp(opt->key, "LogLevel")) {
- log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile");
+ log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile or SysLog");
opt = opt->next;
} else {
- tor_assert(!strcasecmp(opt->key, "LogFile"));
+ tor_assert(!strcasecmp(opt->key, "LogFile") ||
+ !strcasecmp(opt->key, "SysLog"));
if (opt->next && !strcasecmp(opt->next->key, "LogLevel")) {
- /* LogFile followed by LogLevel */
+ /* LogFile/SysLog followed by LogLevel */
if (add_single_log(opt->next, opt, options->RunAsDaemon) < 0)
return -1;
opt = opt->next->next;
} else {
- /* LogFile followed by LogFile or end of list. */
+ /* LogFile/SysLog followed by LogFile/SysLog or end of list. */
if (add_single_log(NULL, opt, options->RunAsDaemon) < 0)
return -1;
opt = opt->next;