]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Add a log-file command line option to the main program.
authorCameron Dale <camrdale@gmail.com>
Tue, 15 Jan 2008 22:50:08 +0000 (14:50 -0800)
committerCameron Dale <camrdale@gmail.com>
Tue, 15 Jan 2008 22:50:08 +0000 (14:50 -0800)
apt-dht.py

index 70a12640b7c7f5481bd86cdb327c80587a1d9853..e5288b0a77b7be3731b101dbe572e5f14e1beb63 100644 (file)
@@ -25,10 +25,11 @@ if __name__ == '__main__':
     # Parse command line parameters when started on command line
     class AptDHTOptions(usage.Options):
         optFlags = [
-            ['help', 'h'],
+            ['help', 'h', 'Print this help message'],
             ]
         optParameters = [
             ['config-file', 'c', [], "Configuration file"],
+            ['log-file', 'l', '-', "File to log to, - for stdout"],
             ]
         longdesc="apt-dht is a peer-to-peer downloader for apt users"
         def opt_version(self):
@@ -43,6 +44,12 @@ if __name__ == '__main__':
         sys.exit(1)
 
     config_file = opts.opts['config-file']
+    log_file = opts.opts['log-file']
+    if log_file == '-':
+        f = sys.stdout
+    else:
+        f = open(log_file, 'w')
+    log.startLogging(f, setStdout=1)
 
 config.read(config_file)
 if config.has_option('DEFAULT', 'username') and config.get('DEFAULT', 'username'):
@@ -73,7 +80,6 @@ else:
 
 if __name__ == '__main__':
     # Run on command line
-    log.startLogging(sys.stdout, setStdout=0)
     service.IServiceCollection(application).privilegedStartService()
     service.IServiceCollection(application).startService()
     reactor.run()