In the wake of changes to hide away tracebacks from players, made the error report include the server log time stamp so as to make it easier to reconcile with the real traceback information.

This commit is contained in:
Griatch 2015-11-09 15:07:06 +01:00
parent d3e218e439
commit 652bb02bc7
2 changed files with 54 additions and 8 deletions

View file

@ -80,16 +80,28 @@ _SEARCH_AT_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit
# Output strings
_ERROR_UNTRAPPED = "An untrapped error occurred. Please file a bug report."
_ERROR_UNTRAPPED = """
An untrapped error occurred. Please file a bug report detailing the
steps to reproduce. Server log time stamp is '{timestamp}'.
"""
_ERROR_CMDSETS = "A cmdset merger error occurred. Please file a bug report."
_ERROR_CMDSETS = """
A cmdset merger error occurred. Please file a bug report detailing the
steps to reproduce. Server log time stamp is '{timestamp}'.
"""
_ERROR_NOCMDSETS = "No command sets found! This is a sign of a critical bug." \
"\nThe error was logged. If disconnecting/reconnecting doesn't" \
"\nsolve the problem, try to contact the server admin through" \
"\nsome other means for assistance."
_ERROR_NOCMDSETS = """
No command sets found! This is a sign of a critical bug. If
disconnecting/reconnecting doesn't" solve the problem, try to contact
the server admin through" some other means for assistance. Server log
time stamp is '{timestamp}'.
"""
_ERROR_CMDHANDLER = "A command handler bug occurred. Please file a bug report with the Evennia project."
_ERROR_CMDHANDLER = """
A command handler bug occurred. Please file a bug report with the
Evennia project. Include the relvant traceback from the server log at
time stamp '{timestamp}'.
"""
_ERROR_RECURSION_LIMIT = "Command recursion limit ({recursion_limit}) " \
"reached for '{raw_string}' ({cmdclass})."
@ -104,7 +116,7 @@ def _msg_err(receiver, string):
string (str): string which will be shown to the user.
"""
receiver.msg(string.format(_nomulti=True))
receiver.msg(string.format(_nomulti=True, timestamp=logger.timeformat()).strip())
# custom Exceptions

View file

@ -13,7 +13,11 @@ log_typemsg(). This is for historical, back-compatible reasons.
"""
from __future__ import division
import os
import time
from datetime import datetime
from traceback import format_exc
from twisted.python import log
from twisted.internet.threads import deferToThread
@ -22,6 +26,36 @@ from twisted.internet.threads import deferToThread
_LOGDIR = None
_TIMEZONE = None
def timeformat(when=None):
"""
This helper function will format the current time in the same
way as twisted's logger does, including time zone info.
Args:
when (int, optional): This is a time in POSIX seconds on the form
given by time.time(). If not given, this function will
use the current time.
Returns:
timestring (str): A formatted string of the given time.
"""
when = when if when else time.time()
# time zone offset: UTC - the actual offset
tz_offset = datetime.utcfromtimestamp(when) - datetime.fromtimestamp(when)
tz_offset = tz_offset.days * 86400 + tz_offset.seconds
# correct given time to utc
when = datetime.utcfromtimestamp(when - tz_offset)
tz_hour = abs(int(tz_offset // 3600))
tz_mins = abs(int(tz_offset // 60 % 60))
tz_sign = "-" if tz_offset >= 0 else "+"
return '%d-%02d-%02d %02d:%02d:%02d%s%02d%02d' % (
when.year, when.month, when.day,
when.hour, when.minute, when.second,
tz_sign, tz_hour, tz_mins)
def log_trace(errmsg=None):
"""
Log a traceback to the log. This should be called from within an