Files
jarvis-models/main.py
0Xiao0 d2ac2e716d fixup
2025-02-06 09:53:47 +08:00

49 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import uvicorn
import logging
from injector import Injector
from src.configuration import singleton
# TODO: 當 skip_ssl 功能加入主分支後移除複制的代嗎改為使用pip安裝依賴。
from src.loki_logger_handler.loki_logger_handler import LokiLoggerHandler
import yaml
@singleton
class Main():
def init_log_handlers(self):
with open(".env.yaml", "r") as file:
config = yaml.safe_load(file)
if config["log"] is None:
return
if config["log"]["handlers"] is None:
return
log_handler_confg = config["log"]["handlers"]
log_handlers = []
for handler_config in log_handler_confg:
if handler_config["type"] == "loki":
log_handlers.append(LokiLoggerHandler(
url=handler_config["url"],
additional_headers={"X-Odin-Auth": handler_config["x-odin-auth"]},
labels=handler_config["labels"],
label_keys={},
timeout=10,
enable_structured_loki_metadata=True,
loki_metadata={"service": "user-service", "version": "1.0.0"},
insecure_ssl_verify=False
))
logging.basicConfig(level=logging.DEBUG, handlers=log_handlers)
logging.info("logging init finish")
def __init__(self) -> None:
self.init_log_handlers()
def run(self):
logger = logging.getLogger(__name__)
logger.info("jarvis-models start", extra={"version": "0.0.1"})
uvicorn.run("server:app", host="0.0.0.0", port=8000, log_level="info",reload = True)
if __name__ == "__main__":
injector = Injector()
main = injector.get(Main)
main.run()