]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add SyslogIdentityTag
authorPeter Palfrader <peter@palfrader.org>
Wed, 30 Sep 2015 15:54:56 +0000 (17:54 +0200)
committerNick Mathewson <nickm@torproject.org>
Wed, 30 Sep 2015 16:34:15 +0000 (18:34 +0200)
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.

changes/bug17194 [new file with mode: 0644]
doc/tor.1.txt
src/common/log.c
src/common/torlog.h
src/or/config.c
src/or/or.h

diff --git a/changes/bug17194 b/changes/bug17194
new file mode 100644 (file)
index 0000000..26549b3
--- /dev/null
@@ -0,0 +1,7 @@
+  o Minor feature:
+    - 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".
+
index 954c8fa243ea15f7a2c820a78dd585f820b75986..b04d57b0d1253f954a890ff0ed77060a5e0fea71 100644 (file)
@@ -580,6 +580,10 @@ GENERAL OPTIONS
     If 1, Tor will overwrite logs at startup and in response to a HUP signal,
     instead of appending to them. (Default: 0)
 
+[[SyslogIdentityTag]] **SyslogIdentityTag** __tag__::
+    When logging to syslog, adds a tag to the syslog identity such that
+    log entries are marked with "Tor-__tag__".  (Default: none)
+
 [[SafeLogging]] **SafeLogging** **0**|**1**|**relay**::
     Tor can scrub potentially sensitive strings from log messages (e.g.
     addresses) by replacing them with the string [scrubbed]. This way logs can
index e23691b6abd79d002ca14edd9585717db72f17e9..8d1c40c36e5a68dfabfb46a681f6f98e2a30161f 100644 (file)
@@ -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;
index 67edf14c04505fb6d1e014744ba1a69d9c376f0e..57679b5f5c5b9376b75303ec5a5368f00cfa04e5 100644 (file)
@@ -135,7 +135,7 @@ void add_stream_log(const log_severity_list_t *severity, const char *name,
 int add_file_log(const log_severity_list_t *severity, const char *filename,
                  const int truncate);
 #ifdef HAVE_SYSLOG_H
-int add_syslog_log(const log_severity_list_t *severity);
+int add_syslog_log(const log_severity_list_t *severity, const char* syslog_identity_tag);
 #endif
 int add_callback_log(const log_severity_list_t *severity, log_callback cb);
 void logs_set_domain_logging(int enabled);
index fa860af3374b9ab30bdacc610954b97c09572dc3..9b65addeeb51b117fd0f01c229cf38aa3f2da9e7 100644 (file)
@@ -312,6 +312,7 @@ static config_var_t option_vars_[] = {
   V(LogMessageDomains,           BOOL,     "0"),
   V(LogTimeGranularity,          MSEC_INTERVAL, "1 second"),
   V(TruncateLogFile,             BOOL,     "0"),
+  V(SyslogIdentityTag,           STRING,   NULL),
   V(LongLivedPorts,              CSV,
         "21,22,706,1863,5050,5190,5222,5223,6523,6667,6697,8300"),
   VAR("MapAddress",              LINELIST, AddressMap,           NULL),
@@ -4937,7 +4938,7 @@ options_init_logs(const or_options_t *old_options, or_options_t *options,
         !strcasecmp(smartlist_get(elts,0), "syslog")) {
 #ifdef HAVE_SYSLOG_H
       if (!validate_only) {
-        add_syslog_log(severity);
+        add_syslog_log(severity, options->SyslogIdentityTag);
       }
 #else
       log_warn(LD_CONFIG, "Syslog is not supported on this system. Sorry.");
index 4496cbcec3319a79b60bf09cbc094aa28c37ca38..a80cd55b5375a1f9929b126394e191f1bd5981b9 100644 (file)
@@ -3424,6 +3424,7 @@ typedef struct {
                           * each log message occurs? */
   int TruncateLogFile; /**< Boolean: Should we truncate the log file
                             before we start writing? */
+  char *SyslogIdentityTag; /**< Identity tag to add for syslog logging. */
 
   char *DebugLogFile; /**< Where to send verbose log messages. */
   char *DataDirectory; /**< OR only: where to store long-term data. */