commit 1a036dc350f2ed20ecdc5a52ea7365b899c0f857 Author: Damian Johnson atagar@torproject.org Date: Sat Dec 21 16:47:41 2013 -0800
Moving debug_log_path to config
I dislike creating configurations at startup. Sometimes it's necessary (such as for the start time) but for debug_log_path we're usually fine with the unexpanded form. Just expanding it for when it's used - as a result we display the collapsed form ('~/path') for --help output and log messages. --- arm/arguments.py | 4 ++-- arm/settings.cfg | 1 + arm/starter.py | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/arm/arguments.py b/arm/arguments.py index aa90ed7..31ec806 100644 --- a/arm/arguments.py +++ b/arm/arguments.py @@ -10,7 +10,7 @@ import stem.connection import stem.util.conf
CONFIG = stem.util.conf.config_dict("arm", { - 'attribute.debug_log_path': '', + 'debug_log_path': '', 'msg.event_types': '', 'msg.help': '', }) @@ -110,7 +110,7 @@ def get_help(): port = DEFAULT_ARGS['control_port'], socket = DEFAULT_ARGS['control_socket'], config = DEFAULT_ARGS['config'], - debug_path = CONFIG['attribute.debug_log_path'], + 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 a69869f..46e88b4 100644 --- a/arm/settings.cfg +++ b/arm/settings.cfg @@ -1,4 +1,5 @@ settings_loaded true +debug_log_path ~/.arm/log
msg.help |Usage arm [OPTION] diff --git a/arm/starter.py b/arm/starter.py index fd96236..edb8e27 100644 --- a/arm/starter.py +++ b/arm/starter.py @@ -36,7 +36,7 @@ import stem.util.system SETTINGS_PATH = os.path.join(os.path.dirname(__file__), 'settings.cfg')
CONFIG = stem.util.conf.config_dict("arm", { - 'attribute.debug_log_path': '', + 'debug_log_path': '', 'tor.password': None, 'startup.events': 'N3', 'msg.debug_header': '', @@ -149,17 +149,18 @@ def _authenticate(controller, password):
def _setup_debug_logging(): """ - Configures us to log at stem's trace level to 'attribute.debug_log_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_dir = os.path.dirname(CONFIG['attribute.debug_log_path']) + debug_path = os.path.expanduser(CONFIG['debug_log_path']) + debug_dir = os.path.dirname(debug_path)
if not os.path.exists(debug_dir): os.makedirs(debug_dir)
- debug_handler = logging.FileHandler(CONFIG['attribute.debug_log_path'], mode = 'w') + debug_handler = logging.FileHandler(debug_path, mode = 'w') debug_handler.setLevel(stem.util.log.logging_level(stem.util.log.TRACE)) debug_handler.setFormatter(logging.Formatter( fmt = '%(asctime)s [%(levelname)s] %(message)s', @@ -209,7 +210,6 @@ def _shutdown_daemons(): def main(): config = stem.util.conf.get_config("arm") config.set('attribute.start_time', str(int(time.time()))) - config.set('attribute.debug_log_path', os.path.expanduser("~/.arm/log"))
try: _load_settings() @@ -233,7 +233,7 @@ def main(): try: _setup_debug_logging() except IOError as exc: - print "Unable to write to our debug log file (%s): %s" % (CONFIG['attribute.debug_log_path'], exc.strerror) + print "Unable to write to our debug log file (%s): %s" % (CONFIG['debug_log_path'], exc.strerror) sys.exit(1)
stem.util.log.trace(CONFIG['msg.debug_header'].format( @@ -246,7 +246,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['attribute.debug_log_path'] + print "Saving a debug log to %s, please check it for sensitive information before sharing" % CONFIG['debug_log_path']
# loads user's personal armrc if available
tor-commits@lists.torproject.org