-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
40 lines (29 loc) · 1.01 KB
/
logger.py
File metadata and controls
40 lines (29 loc) · 1.01 KB
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
"""Logging setup for GEM BidPlus. When GEM_DEBUG=1 writes to file and console with verbose level."""
import logging
import os
import sys
from utils import config
def setup_logger(name: str = "gem_automation") -> logging.Logger:
"""Configure and return the logger."""
log = logging.getLogger(name)
if log.handlers:
return log
log.setLevel(logging.DEBUG if config.DEBUG else logging.INFO)
fmt = logging.Formatter(
"%(asctime)s | %(levelname)-7s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(fmt)
log.addHandler(handler)
if config.DEBUG:
config._ensure_debug_dirs()
file_handler = logging.FileHandler(
os.path.join(config.LOG_DIR, "gem_automation.log"),
encoding="utf-8",
)
file_handler.setFormatter(fmt)
file_handler.setLevel(logging.DEBUG)
log.addHandler(file_handler)
return log
logger = setup_logger()