-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.py
73 lines (51 loc) · 1.89 KB
/
log.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
PINK = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
import logging
from dhooks import Webhook, File, Embed #this util allows us to log to discord easily
import json
import config
hook = None
if config.config["discord_webhook_logging"] != "":
hook = Webhook(config.config["discord_webhook_logging"])
logging.basicConfig( format='[%(asctime)s] %(levelname)s - %(message)s',
level=logging.DEBUG if config.config["debug"] else logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
logger = logging.getLogger()
def debug(message:str,color:str = None):
"""message, *color"""
if color:
message = color + message + ENDC
logger.debug(message)
def info(message:str,color:str = None):
"""message, *color"""
if color:
message = color + message + ENDC
logger.info(message)
def warning(message:str,color:str = None):
"""message, *color"""
if hook != None:
embed = Embed(title = "Warning",description = message,timestamp = "now",color=0xFFA500)
hook.send(embed=embed)
if color:
message = color + message + ENDC
# TODO: add option for logging to other external services(datadog, etc)
logger.warning(message)
def error(message:str,color:str = None):
"""message, *color"""
#TODO: not all errors are sent because they arent sent through log.py. Is there a way to include them?
if hook != None:
embed = Embed(title = "Error",description = message,timestamp = "now",color=0xFF0000)
hook.send(embed=embed)
if color:
message = color + message + ENDC
# TODO: add option for logging to other external services(datadog, etc)
logger.error(message)
def blame(user,message): #TODO: More elegant way of doing this?
if config.config["blame_logging"]:
print("Server blames %s for %s" % (user,message))