From 652bb02bc70f1bb009759f62698eef3d3faf6bb2 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 9 Nov 2015 15:07:06 +0100 Subject: [PATCH] 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. --- evennia/commands/cmdhandler.py | 28 ++++++++++++++++++++-------- evennia/utils/logger.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 3d5afa34d5..4ecdb6f303 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -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 diff --git a/evennia/utils/logger.py b/evennia/utils/logger.py index 3749259195..66545d32b5 100644 --- a/evennia/utils/logger.py +++ b/evennia/utils/logger.py @@ -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