From d1d2930c9ecfd68235c4d8d853546180ed4889f4 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Tue, 15 Jan 2008 14:50:08 -0800 Subject: [PATCH] Add a log-file command line option to the main program. --- apt-dht.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apt-dht.py b/apt-dht.py index 70a1264..e5288b0 100644 --- a/apt-dht.py +++ b/apt-dht.py @@ -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() -- 2.39.5