-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
36 lines (28 loc) · 964 Bytes
/
logger.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
import logging
from environment import *
class CustomFormatter(logging.Formatter):
grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
FORMATS = {
logging.DEBUG: grey + format + reset,
logging.INFO: grey + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
}
def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
log = logging.getLogger('geth-peer-sidecar')
# Initial logging setup
log.setLevel(logging_level)
ch = logging.StreamHandler()
ch.setLevel(logging_level)
ch.setFormatter(CustomFormatter())
log.addHandler(ch)
log.info("Loaded environment variables...")