add debug option

This commit is contained in:
Thor77 2015-06-21 21:28:14 +02:00
parent 90bfa04696
commit 1eb8b3b0d6
2 changed files with 9 additions and 3 deletions

View File

@ -11,12 +11,15 @@
</head> </head>
<body> <body>
<div id="container"> <div id="container">
{% if debug %}
<div class="alert alert-danger" role="alert" style="text-align: center;"><b>DEBUG</b></div>
{% endif %}
{% for headline, list in objs %} {% for headline, list in objs %}
{% if list|length > 0 %} {% if list|length > 0 %}
<h1>{{ headline }}</h2> <h1>{{ headline }}</h2>
<ul class="list-group"> <ul class="list-group">
{% for client, value in list %} {% for client, value in list %}
<li class="list-group-item{{ ' list-group-item-success' if client.connected else loop.cycle('" style="background-color: #eee;', '') }}">{{ client.nick }}<span class="badge">{{ value }}</span></li> <li class="list-group-item{{ ' list-group-item-success' if client.connected else loop.cycle('" style="background-color: #eee;', '') }}">{{ client.nick }}{{ " (" + client.identifier + ")" if debug }}<span class="badge">{{ value }}</span></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}

View File

@ -14,7 +14,7 @@ log = logging.getLogger()
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
# create handler # create handler
file_handler = logging.FileHandler('debug.txt', 'w', 'UTF-8') file_handler = logging.FileHandler('debug.txt', 'w', 'UTF-8')
file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(message)s', '%d.%m.%Y %H:%M:%S')) file_handler.setFormatter(logging.Formatter('%(message)s'))
file_handler.setLevel(logging.DEBUG) file_handler.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler() stream_handler = logging.StreamHandler()
@ -144,7 +144,10 @@ log_path = general['logfile']
if not exists(log_path): if not exists(log_path):
raise Exception('Couldn\'t access log-file!') raise Exception('Couldn\'t access log-file!')
output_path = general['outputfile'] output_path = general['outputfile']
debug = general.get('debug', 'true') in ['true', 'True']
title = html.get('title', 'TeamspeakStats') title = html.get('title', 'TeamspeakStats')
if not debug:
logging.disable(logging.DEBUG)
generation_start = datetime.datetime.now() generation_start = datetime.datetime.now()
@ -209,4 +212,4 @@ objs = [('Onlinetime', clients_onlinetime), ('Kicks', clients_kicks),
('Bans', clients_bans), ('passive Bans', clients_pbans)] # (headline, list) ('Bans', clients_bans), ('passive Bans', clients_pbans)] # (headline, list)
with open(output_path, 'w') as f: with open(output_path, 'w') as f:
f.write(template.render(title=title, objs=objs, generation_time='{}.{}'.format(generation_delta.seconds, generation_delta.microseconds), time=generation_end.strftime('%d.%m.%Y %H:%M'))) f.write(template.render(title=title, objs=objs, generation_time='{}.{}'.format(generation_delta.seconds, generation_delta.microseconds), time=generation_end.strftime('%d.%m.%Y %H:%M'), debug=debug))