summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/reactor_manager.py24
-rw-r--r--service/pixelated/user_agent.py7
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__':