added error logging into webapp

This commit is contained in:
Micah Lee 2014-06-19 16:59:36 -04:00
parent 03d2053eff
commit f3e31cab31

View file

@ -1,5 +1,5 @@
from flask import Flask, render_template
import threading, json, os, time
import threading, json, os, time, platform
onionshare = None
onionshare_port = None
@ -10,7 +10,24 @@ clipboard = None
url = None
# figure out this platform's temp dir
if platform.system() == 'Windows':
temp_dir = os.environ['Temp'].replace('\\', '/')
else:
temp_dir = '/tmp/'
# suppress output in windows
if platform.system() == 'Windows':
sys.stdout = open('{0}/onionshare.stdout.log'.format(temp_dir), 'w')
sys.stderr = open('{0}/onionshare.stderr.log'.format(temp_dir), 'w')
# log web errors to file
import logging
log_handler = logging.FileHandler('{0}/onionshare.web.log'.format(temp_dir))
log_handler.setLevel(logging.WARNING)
app = Flask(__name__, template_folder='./templates')
app.logger.addHandler(log_handler)
@app.route("/")
def index():