diff options
author | Peter Palfrader <peter@palfrader.org> | 2015-09-30 17:54:56 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-09-30 18:34:15 +0200 |
commit | 1cf0d82280973a52403c160fa47a4fb06dfca6c3 (patch) | |
tree | c22b791c38b3cb06d7abe7186d5839bc7fabf792 /src/common/log.c | |
parent | 0d43a54d1c9c1be24c33eed79029d1bd44a6a28a (diff) | |
download | tor-1cf0d82280973a52403c160fa47a4fb06dfca6c3.tar.gz tor-1cf0d82280973a52403c160fa47a4fb06dfca6c3.zip |
Add SyslogIdentityTag
When logging to syslog, allow a tag to be added to the syslog identity
("Tor"), i.e. the string prepended to every log message. The tag can be
configured by setting SyslogIdentityTag and defaults to none. Setting
it to "foo" will cause logs to be tagged as "Tor-foo". Closes: #17194.
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/log.c b/src/common/log.c index e23691b6ab..8d1c40c36e 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -1099,12 +1099,19 @@ add_file_log(const log_severity_list_t *severity, const char *filename, * Add a log handler to send messages to they system log facility. */ int -add_syslog_log(const log_severity_list_t *severity) +add_syslog_log(const log_severity_list_t *severity, const char* syslog_identity_tag) { logfile_t *lf; - if (syslog_count++ == 0) + if (syslog_count++ == 0) { /* This is the first syslog. */ - openlog("Tor", LOG_PID | LOG_NDELAY, LOGFACILITY); + static char buf[256]; + if (syslog_identity_tag) { + tor_snprintf(buf, sizeof(buf), "Tor-%s", syslog_identity_tag); + } else { + tor_snprintf(buf, sizeof(buf), "Tor"); + } + openlog(buf, LOG_PID | LOG_NDELAY, LOGFACILITY); + } lf = tor_malloc_zero(sizeof(logfile_t)); lf->fd = -1; |