-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.py
64 lines (57 loc) · 2.03 KB
/
entrypoint.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
"""This is an entrypoint specific for docker containers."""
import os
import pathlib
from datetime import datetime
import vaultapi
logs_dir = os.path.join(pathlib.Path(__file__).parent, "logs")
db_file = os.environ.get("database") or os.environ.get("DATABASE") or "secrets.db"
db_path = os.path.join(pathlib.Path(__file__).parent, "data", db_file)
DEFAULT_LOG_FILENAME: str = datetime.now().strftime(
os.path.join(logs_dir, "vaultapi_%d-%m-%Y.log")
)
os.makedirs(logs_dir, exist_ok=True)
log_config = {
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(asctime)s %(levelprefix)-9s %(name)s -: %(message)s",
"use_colors": False,
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"fmt": '%(asctime)s %(levelprefix)-9s %(name)s -: %(client_addr)s - "%(request_line)s" %(status_code)s',
"use_colors": False,
},
"error": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(asctime)s %(levelprefix)-9s %(name)s -: %(message)s",
"use_colors": False,
},
},
"handlers": {
"default": {
"class": "logging.FileHandler",
"formatter": "default",
"filename": DEFAULT_LOG_FILENAME,
},
"access": {
"class": "logging.FileHandler",
"formatter": "access",
"filename": DEFAULT_LOG_FILENAME,
},
"error": {
"class": "logging.FileHandler",
"formatter": "error",
"filename": DEFAULT_LOG_FILENAME,
},
},
"loggers": {
"uvicorn": {"propagate": True, "level": "INFO", "handlers": ["default"]},
"uvicorn.error": {"propagate": True, "level": "INFO", "handlers": ["error"]},
"uvicorn.access": {"propagate": True, "level": "INFO", "handlers": ["access"]},
},
}
if __name__ == "__main__":
vaultapi.start(log_config=log_config, database=db_path)