-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils.py
37 lines (30 loc) · 1004 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from typing import Literal
from datetime import datetime
import time
import sys
import traceback
"""
Meower Utils Module
This module provides logging, error traceback, and other miscellaneous utilities.
This file should never rely on other Meower modules to prevent circular imports.
"""
def full_stack():
"""
Print out the full traceback.
"""
exc = sys.exc_info()[0]
if exc is not None:
f = sys.exc_info()[-1].tb_frame.f_back
stack = traceback.extract_stack(f)
else:
stack = traceback.extract_stack()[:-1]
trc = 'Traceback (most recent call last):\n'
stackstr = trc + ''.join(traceback.format_list(stack))
if exc is not None:
stackstr += ' ' + traceback.format_exc().lstrip(trc)
return stackstr
def log(event: str):
"""
Print out a log with the current date & time to the Python console.
"""
print("{0}: {1}".format(datetime.now().strftime("%m/%d/%Y %H:%M.%S"), event))