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:
parent
d3e218e439
commit
652bb02bc7
2 changed files with 54 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue