diff options
author | Patrick Maia and Victor Shyba <pixelated-team+pmaia+vshyba@thoughtworks.com> | 2014-08-22 16:19:25 +0000 |
---|---|---|
committer | Patrick Maia <pmaia@thoughtworks.com> | 2014-08-22 17:13:22 +0000 |
commit | 285f3e706195631e1094791e0399de4530f9a70d (patch) | |
tree | 4adb76b27a3aa6a39b0dce4c69dfa92abf35c7b9 /service/pixelated | |
parent | 797d8553959cf9f3998eb753f42349f92e2f52fd (diff) |
adds log capacity to pixelated user agent
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/reactor_manager.py | 24 | ||||
-rw-r--r-- | service/pixelated/user_agent.py | 7 |
2 files changed, 27 insertions, 4 deletions
diff --git a/service/pixelated/reactor_manager.py b/service/pixelated/reactor_manager.py index 01f7f545..6b9b3f86 100644 --- a/service/pixelated/reactor_manager.py +++ b/service/pixelated/reactor_manager.py @@ -2,14 +2,17 @@ import signal import sys from threading import Thread from twisted.internet import reactor - +import logging def signal_handler(signal, frame): stop_reactor_on_exit() sys.exit(0) -def start_reactor(): +def start_reactor(logging=False): + if logging: + enable_logging() + def start_reactor_run(): reactor.run(False) @@ -24,3 +27,20 @@ def stop_reactor_on_exit(): REACTOR_THREAD = None signal.signal(signal.SIGINT, signal_handler) + +def enable_logging(): + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + datefmt='%m-%d %H:%M', + filename='/tmp/leap.log', + filemode='w') + + # define a Handler which writes INFO messages or higher to the sys.stderr + console = logging.StreamHandler() + console.setLevel(logging.DEBUG) + # set a format which is simpler for console use + formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + # tell the handler to use this format + console.setFormatter(formatter) + # add the handler to the root logger + logging.getLogger('').addHandler(console) diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index c4278725..8737d8c6 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -1,4 +1,5 @@ import json +import os import datetime import dateutil.parser as dateparser @@ -131,10 +132,12 @@ def index(): def setup(): - reactor_manager.start_reactor() + debug_enabled = os.environ.get('DEBUG', False) + reactor_manager.start_reactor(logging=debug_enabled) app.config.from_pyfile('../config/pixelated_ua.cfg') account = app.config['ACCOUNT'] - app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT']) + app.config['DEBUG'] = debug_enabled + app.run(host=app.config['HOST'], debug=debug_enabled, port=app.config['PORT']) if __name__ == '__main__': |