[or-cvs] clean up logging, allow user to specify log files

Roger Dingledine arma at seul.org
Wed Oct 15 18:50:18 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	config.c connection.c connection_edge.c main.c or.h 
Log Message:
clean up logging, allow user to specify log files

If DebugLogFile is specified, log to it at -l debug
If LogFile is specified, log to it at the -l from the commandline
  (default info)
If no LogFile *and* not a Daemon, then log to stdout.
Make conn->s = -1 by default (this might break things)
When kill -USR1, prefer to log at INFO, but make sure they always see it.



Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- config.c	15 Oct 2003 07:19:38 -0000	1.58
+++ config.c	15 Oct 2003 18:50:16 -0000	1.59
@@ -151,6 +151,8 @@
 
     /* string options */
     config_compare(list, "LogLevel",       CONFIG_TYPE_STRING, &options->LogLevel) ||
+    config_compare(list, "LogFile",        CONFIG_TYPE_STRING, &options->LogFile) ||
+    config_compare(list, "DebugLogFile",   CONFIG_TYPE_STRING, &options->DebugLogFile) ||
     config_compare(list, "DataDirectory",  CONFIG_TYPE_STRING, &options->DataDirectory) ||
     config_compare(list, "RouterFile",     CONFIG_TYPE_STRING, &options->RouterFile) ||
     config_compare(list, "PidFile",        CONFIG_TYPE_STRING, &options->PidFile) ||
@@ -171,10 +173,10 @@
     config_compare(list, "NumCpus",         CONFIG_TYPE_INT, &options->NumCpus) ||
 
     config_compare(list, "OnionRouter",     CONFIG_TYPE_BOOL, &options->OnionRouter) ||
-    config_compare(list, "Daemon",          CONFIG_TYPE_BOOL, &options->Daemon) ||
     config_compare(list, "TrafficShaping",  CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
     config_compare(list, "LinkPadding",     CONFIG_TYPE_BOOL, &options->LinkPadding) ||
     config_compare(list, "IgnoreVersion",   CONFIG_TYPE_BOOL, &options->IgnoreVersion) ||
+    config_compare(list, "RunAsDaemon",     CONFIG_TYPE_BOOL, &options->RunAsDaemon) ||
 
     /* float options */
     config_compare(list, "CoinWeight",     CONFIG_TYPE_DOUBLE, &options->CoinWeight)
@@ -201,7 +203,7 @@
   memset(options,0,sizeof(or_options_t));
   options->LogLevel = "info";
   options->ExitPolicy = "reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*";
-  options->loglevel = LOG_DEBUG;
+  options->loglevel = LOG_INFO;
   options->PidFile = "tor.pid";
   options->DataDirectory = NULL;
   options->CoinWeight = 0.1;

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- connection.c	15 Oct 2003 18:28:32 -0000	1.121
+++ connection.c	15 Oct 2003 18:50:16 -0000	1.122
@@ -78,6 +78,7 @@
 
   conn = (connection_t *)tor_malloc(sizeof(connection_t));
   memset(conn,0,sizeof(connection_t)); /* zero it out to start */
+  conn->s = -1; /* give it a default of 'not used' */
 
   conn->type = type;
   if(!connection_is_listener(conn)) { /* listeners never use their buf */
@@ -117,7 +118,7 @@
   if (conn->nickname) 
     free(conn->nickname);
 
-  if(conn->s > 0) {
+  if(conn->s >= 0) {
     log_fn(LOG_INFO,"closing fd %d.",conn->s);
     close(conn->s);
   }

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- connection_edge.c	14 Oct 2003 01:10:22 -0000	1.40
+++ connection_edge.c	15 Oct 2003 18:50:16 -0000	1.41
@@ -557,7 +557,7 @@
   n_stream->address = tor_strdup(cell->payload + RELAY_HEADER_SIZE + STREAM_ID_SIZE);
   n_stream->port = atoi(colon+1);
   n_stream->state = EXIT_CONN_STATE_RESOLVING;
-  n_stream->s = -1; /* not yet valid */
+  /* leave n_stream->s at -1, because it's not yet valid */
   n_stream->package_window = STREAMWINDOW_START;
   n_stream->deliver_window = STREAMWINDOW_START;
   if(connection_add(n_stream) < 0) { /* no space, forget it */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- main.c	15 Oct 2003 18:37:19 -0000	1.132
+++ main.c	15 Oct 2003 18:50:16 -0000	1.133
@@ -601,7 +601,8 @@
   for(;;) {
 #ifndef MS_WIN32 /* do signal stuff only on unix */
     if(please_dumpstats) {
-      dumpstats(LOG_INFO);
+      /* prefer to log it at INFO, but make sure we always see it */
+      dumpstats(options.loglevel>LOG_INFO ? options.loglevel : LOG_INFO);
       please_dumpstats = 0;
     }
     if(please_reset) {
@@ -774,14 +775,21 @@
     log_fn(LOG_ERR,"Reading config file failed. exiting.");
     return -1;
   }
-  log_set_severity(options.loglevel);     /* assign logging severity level from options */
+  log_set_severity(options.loglevel); /* assign logging severity level from options */
+  if(options.DebugLogFile)
+    add_file_log(LOG_DEBUG, options.DebugLogFile);
+  if(options.LogFile)
+    add_file_log(options.loglevel, options.LogFile);
+  if(!options.LogFile && !options.RunAsDaemon)
+    add_stream_log(options.loglevel, "<stdout>", stdout);
+
   global_read_bucket = options.TotalBandwidth; /* start it at 1 second of traffic */
   stats_prev_global_read_bucket = global_read_bucket;
 
   /* write our pid to the pid file */
   write_pidfile(options.PidFile);
 
-  if(options.Daemon)
+  if(options.RunAsDaemon)
     daemonize();
 
   if(options.OnionRouter) { /* only spawn dns handlers if we're a router */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- or.h	15 Oct 2003 18:37:19 -0000	1.166
+++ or.h	15 Oct 2003 18:50:16 -0000	1.167
@@ -416,6 +416,8 @@
 
 typedef struct {
    char *LogLevel;
+   char *LogFile;
+   char *DebugLogFile;
    char *DataDirectory;
    char *RouterFile;
    char *Nickname;
@@ -423,7 +425,6 @@
    char *PidFile;
    char *ExitPolicy;
    double CoinWeight;
-   int Daemon;
    int ORPort;
    int APPort;
    int DirPort;
@@ -432,6 +433,7 @@
    int TrafficShaping;
    int LinkPadding;
    int IgnoreVersion;
+   int RunAsDaemon;
    int DirRebuildPeriod;
    int DirFetchPostPeriod;
    int KeepalivePeriod;



More information about the tor-commits mailing list