This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
71 lines (67 loc) · 2.4 KB
/
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
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
from logging.config import dictConfig
import logging
import os
def setup_logger(service_name):
log_path = "tradutor/log/"
# Verifica se o diretorio para anexar os logs não existe
if not os.path.exists(log_path):
# Então cria o diretorio
os.makedirs(log_path)
dictConfig({
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"default": {
"format": "[%(asctime)s] %(levelname)-4s %(funcName)s() L%(lineno)-4d %(message)s",
},
"detailed": {
"format": "[%(asctime)s] %(levelname)-4s %(funcName)s() L%(lineno)-4d %(message)s - call_trace=%(pathname)s L%(lineno)-4d",
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
"stream": "ext://sys.stdout",
},
# "email": {
# "class": "logging.handlers.SMTPHandler",
# "formatter": "default",
# "level": "ERROR",
# "mailhost": ("smtp.example.com", 587),
# "fromaddr": "[email protected]",
# "toaddrs": ["[email protected]", "[email protected]"],
# "subject": "Error Logs",
# "credentials": ("username", "password"),
# },
"error_file": {
"class": "logging.handlers.RotatingFileHandler",
"formatter": "detailed",
"filename": f"tradutor/log/{service_name}.error.log",
"maxBytes": 10000,
"backupCount": 10,
"delay": "True",
},
"detailed_file": {
"class": "logging.handlers.RotatingFileHandler",
"formatter": "detailed",
"filename": f"tradutor/log/{service_name}.detailed.log",
"maxBytes": 10000,
"backupCount": 10,
"delay": "True",
}
},
"loggers": {
f"{service_name}.error": {
"handlers": ["console", "error_file"], #, email],
"level": "INFO",
"propagate": False,
}
},
"root": {
"handlers": ["console", "detailed_file"],
"level": "INFO",
}
})
logger = logging.getLogger(__name__)
return logger