commit 048fa24b55b53a3d4661240c97c6efe0a14b5cfc Author: Damian Johnson atagar@torproject.org Date: Sat Dec 21 16:59:04 2013 -0800
Making debug location customizable
Now that I think about it, why default the log to ~/.arm/log? People (hopefully) use the --debug argument so rarely they won't know where to look. Having them supply the path instead. --- arm/arguments.py | 10 ++++------ arm/settings.cfg | 3 +-- arm/starter.py | 10 ++++------ test/arguments.py | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/arm/arguments.py b/arm/arguments.py index 31ec806..c7eeb08 100644 --- a/arm/arguments.py +++ b/arm/arguments.py @@ -10,7 +10,6 @@ import stem.connection import stem.util.conf
CONFIG = stem.util.conf.config_dict("arm", { - 'debug_log_path': '', 'msg.event_types': '', 'msg.help': '', }) @@ -22,20 +21,20 @@ DEFAULT_ARGS = { 'control_socket': '/var/run/tor/control', 'user_provided_socket': False, 'config': os.path.expanduser("~/.arm/armrc"), - 'debug': False, + 'debug_path': None, 'blind': False, 'logged_events': 'N3', 'print_version': False, 'print_help': False, }
-OPT = "i:s:c:dbe:vh" +OPT = "i:s:c:d:be:vh"
OPT_EXPANDED = [ "interface=", "socket=", "config=", - "debug", + "debug=", "blind", "event=", "version", @@ -82,7 +81,7 @@ def parse(argv): elif opt in ("-c", "--config"): args['config'] = arg elif opt in ("-d", "--debug"): - args['debug'] = True + args['debug_path'] = os.path.expanduser(arg) elif opt in ("-b", "--blind"): args['blind'] = True elif opt in ("-e", "--event"): @@ -110,7 +109,6 @@ def get_help(): port = DEFAULT_ARGS['control_port'], socket = DEFAULT_ARGS['control_socket'], config = DEFAULT_ARGS['config'], - debug_path = CONFIG['debug_log_path'], events = DEFAULT_ARGS['logged_events'], event_flags = CONFIG['msg.event_types'], ) diff --git a/arm/settings.cfg b/arm/settings.cfg index 46e88b4..19f7cc8 100644 --- a/arm/settings.cfg +++ b/arm/settings.cfg @@ -1,5 +1,4 @@ settings_loaded true -debug_log_path ~/.arm/log
msg.help |Usage arm [OPTION] @@ -10,7 +9,7 @@ msg.help | SOCKET_PATH defaults to: {socket} | -c, --config CONFIG_PATH loaded configuration options, CONFIG_PATH | defaults to: {config} -| -d, --debug writes all arm logs to {debug_path} +| -d, --debug LOG_PATH writes all arm logs to the given location | -b, --blind disable connection lookups | -e, --event EVENT_FLAGS event types in message log (default: {events}) |{event_flags} diff --git a/arm/starter.py b/arm/starter.py index edb8e27..1e6fe10 100644 --- a/arm/starter.py +++ b/arm/starter.py @@ -36,7 +36,6 @@ import stem.util.system SETTINGS_PATH = os.path.join(os.path.dirname(__file__), 'settings.cfg')
CONFIG = stem.util.conf.config_dict("arm", { - 'debug_log_path': '', 'tor.password': None, 'startup.events': 'N3', 'msg.debug_header': '', @@ -147,14 +146,13 @@ def _authenticate(controller, password): raise ValueError("Unable to authenticate: %s" % exc)
-def _setup_debug_logging(): +def _setup_debug_logging(debug_path): """ Configures us to log at stem's trace level to debug log path.
:raises: **IOError** if we can't log to this location """
- debug_path = os.path.expanduser(CONFIG['debug_log_path']) debug_dir = os.path.dirname(debug_path)
if not os.path.exists(debug_dir): @@ -229,11 +227,11 @@ def main(): print "arm version %s (released %s)\n" % (arm.__version__, arm.__release_date__) sys.exit()
- if args.debug: + if args.debug_path is not None: try: _setup_debug_logging() except IOError as exc: - print "Unable to write to our debug log file (%s): %s" % (CONFIG['debug_log_path'], exc.strerror) + print "Unable to write to our debug log file (%s): %s" % (args.debug_path, exc.strerror) sys.exit(1)
stem.util.log.trace(CONFIG['msg.debug_header'].format( @@ -246,7 +244,7 @@ def main(): armrc_content = _armrc_dump(args.config), ))
- print "Saving a debug log to %s, please check it for sensitive information before sharing" % CONFIG['debug_log_path'] + print "Saving a debug log to %s, please check it for sensitive information before sharing" % args.debug_path
# loads user's personal armrc if available
diff --git a/test/arguments.py b/test/arguments.py index c7e1168..0e7864f 100644 --- a/test/arguments.py +++ b/test/arguments.py @@ -24,8 +24,8 @@ class TestArgumentParsing(unittest.TestCase): self.assertEqual('/tmp/my_socket', args.control_socket) self.assertEqual('/tmp/my_config', args.config)
- args = parse(['--debug', '--blind']) - self.assertEqual(True, args.debug) + args = parse(['--debug', '/tmp/dump', '--blind']) + self.assertEqual('/tmp/dump', args.debug_path) self.assertEqual(True, args.blind)
args = parse(['--event', 'D1'])
tor-commits@lists.torproject.org