Changeset - 5f9e26cdf064
[Not reviewed]
default
0 2 0
Dennis Fink - 10 years ago 2014-10-17 14:54:42
dennis.fink@c3l.lu
Enable debug_log if user specified it in the webapp config
2 files changed with 11 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/functions.py
Show inline comments
 
@@ -6,6 +6,8 @@ from datetime import datetime
 

	
 
import pygeoip
 

	
 
from flask import current_app
 

	
 
from ennstatus.status.functions import _send_mail
 

	
 

	
 
@@ -74,6 +76,7 @@ def check_json_format(server):
 

	
 
def _send_offline_mail(server_name, last_updated):
 

	
 
    current_app.logger.info('Sending tor status offline mail!')
 
    subject = '[Ennstatus] %s Tor status went offline'
 
    _send_mail(server_name, last_updated, subject)
 
    mail_cache[server_name] = datetime.utcnow()
 
@@ -107,17 +110,24 @@ def update_server(server, ip):
 
    if server['tor_status'] == 'Offline':
 

	
 
        if server_name in mail_cache:
 

	
 
            current_app.logger.debug('Mail cache is %s' % str(mail_cache))
 

	
 
            send_date = mail_cache[server_name]
 
            now = datetime.utcnow()
 
            delta = now - send_date
 

	
 
            if delta.seconds <= 7200:
 
                current_app.logger.debug('Server is in mail cache but not old enough to resend mail')
 
                return server
 
            else:
 
                current_app.logger.debug('Server tor status is offline for more than 7200 seconds')
 
                _send_offline_mail(server_name, server['last_updated'])
 
        else:
 
            current_app.logger.debug('Server is not in mail cache')
 
            _send_offline_mail(server_name, server['last_updated'])
 
    elif server_name in mail_cache:
 
        current_app.logger.debug('Removing server from mail cache')
 
        del mail_cache[server_name]
 

	
 
    return server
ennstatus/log.py
Show inline comments
 
@@ -24,7 +24,7 @@ def init_logging(app):
 
    rotating_file_handler.setLevel(logging.INFO)
 
    rotating_file_handler.setFormatter(logging_formatter)
 

	
 
    if app.debug:
 
    if app.debug or app.config['ENABLE_DEBUG_LOG']:
 
        second_rotating_file_handler = logging.handlers.RotatingFileHandler(
 
            'log/ennstatus_debug.log',
 
            maxBytes=1300000,
0 comments (0 inline, 0 general)