Improve logger to use custom timestamps.
This commit is contained in:
parent
20eda8c5d1
commit
4cc26e3ac2
@ -29,3 +29,6 @@ ALT_CHANNELS = ""
|
|||||||
ALLOWED_ALT_CHANNELS_COMMANDS = []
|
ALLOWED_ALT_CHANNELS_COMMANDS = []
|
||||||
|
|
||||||
USE_UTC = True # if True, will use the UTC time, else the local time
|
USE_UTC = True # if True, will use the UTC time, else the local time
|
||||||
|
# {tzname} and {tzoffset} can both be used; respectively the timezone name (like UTC) and offset in the form +0000
|
||||||
|
# %Y is the year with century, %y is the year without, %m is the month, %d the day, %H hour, %M minute and %S seconds
|
||||||
|
TIMESTAMP_FORMAT = "[%Y-%m-%d %H:%M:%S{tzoffset}]"
|
||||||
|
@ -5,14 +5,19 @@ import time
|
|||||||
def get_timestamp():
|
def get_timestamp():
|
||||||
"""Returns a timestamp with timezone + offset from UTC."""
|
"""Returns a timestamp with timezone + offset from UTC."""
|
||||||
if botconfig.USE_UTC:
|
if botconfig.USE_UTC:
|
||||||
return datetime.datetime.utcnow().strftime("[%Y-%m-%d] (%H:%M:%S) UTC +0000 ")
|
tmf = datetime.datetime.utcnow().strftime(botconfig.TIMESTAMP_FORMAT)
|
||||||
|
if tmf[-1] != " ":
|
||||||
|
tmf += " "
|
||||||
|
return tmf.format(tzname="UTC", tzoffset="+0000")
|
||||||
|
tmf = time.strftime(botconfig.TIMESTAMP_FORMAT)
|
||||||
|
if tmf[-1] != " ":
|
||||||
|
tmf += " "
|
||||||
|
tz = time.strftime("%Z")
|
||||||
utctime = datetime.datetime.utcnow().strftime("%H")
|
utctime = datetime.datetime.utcnow().strftime("%H")
|
||||||
nowtime = datetime.datetime.now().strftime("%H")
|
nowtime = datetime.datetime.now().strftime("%H")
|
||||||
offset = "+" if int(utctime) > int(nowtime) else "-"
|
offset = "-" if int(utctime) > int(nowtime) else "+"
|
||||||
tz = str(time.timezone // 36)
|
offset += str(time.timezone // 36).zfill(4)
|
||||||
if len(tz) == 3:
|
return tmf.format(tzname=tz, tzoffset=offset).upper()
|
||||||
tz = "0" + tz
|
|
||||||
return time.strftime("[%Y-%m-%d] (%H:%M:%S) %Z {0}{1} ").upper().format(offset, tz)
|
|
||||||
|
|
||||||
def logger(file, write=True, display=True):
|
def logger(file, write=True, display=True):
|
||||||
def log(*output, write=write, display=display):
|
def log(*output, write=write, display=display):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user