示例#1
0
    def configure_logging(self) -> None:
        logging.getLogger().handlers = [InterceptHandler()]
        for logger_name in self.loggers:
            logging_logger = logging.getLogger(logger_name)
            logging_logger.handlers = [InterceptHandler(level=self.logging_level)]

        logger.configure(handlers=[{"sink": sys.stderr, "level": self.logging_level}])
示例#2
0
文件: config.py 项目: Choyeon/nuntium
class Settings(BaseSettings):
    API_PREFIX = "/api"
    VERSION = "0.1.0"
    DEBUG: bool = config("DEBUG", cast=bool, default=False)
    MAX_CONNECTIONS_COUNT: int = config("MAX_CONNECTIONS_COUNT",
                                        cast=int,
                                        default=10)
    MIN_CONNECTIONS_COUNT: int = config("MIN_CONNECTIONS_COUNT",
                                        cast=int,
                                        default=10)
    SECRET_KEY: Secret = config("SECRET_KEY", cast=Secret, default="")
    BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []

    PROJECT_NAME: str = config("PROJECT_NAME", default="nuntium")
    FIRST_SUPERUSER = '******'
    FIRST_SUPERUSER_PASSWORD = '******'
    # logging configuration
    LOGGING_LEVEL = logging.DEBUG if DEBUG else logging.INFO

    logger.configure(handlers=[{"sink": sys.stderr, "level": LOGGING_LEVEL}])
    logging.basicConfig(handlers=[InterceptHandler(level=LOGGING_LEVEL)],
                        level=LOGGING_LEVEL)
    MODEL_PATH = config("MODEL_PATH", default="./ml/model/")
    MODEL_NAME = config("MODEL_NAME", default="model.pkl")
    SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db"
示例#3
0
import logging
import sys
from typing import List

from loguru import logger
from starlette.config import Config
from starlette.datastructures import CommaSeparatedStrings, Secret

from app.core.logging import InterceptHandler

config = Config(".env")

API_PREFIX = "/api"
VERSION = "0.0.0"
DEBUG: bool = config("DEBUG", cast=bool, default=False)
MAX_CONNECTIONS_COUNT: int = config("MAX_CONNECTIONS_COUNT",
                                    cast=int,
                                    default=10)
MIN_CONNECTIONS_COUNT: int = config("MIN_CONNECTIONS_COUNT",
                                    cast=int,
                                    default=10)
SECRET_KEY: Secret = config("SECRET_KEY", cast=Secret)

PROJECT_NAME: str = config("PROJECT_NAME", default="FastAPI - Boilerplate")

# logging configuration
LOGGING_LEVEL = logging.DEBUG if DEBUG else logging.INFO
logging.basicConfig(handlers=[InterceptHandler(level=LOGGING_LEVEL)],
                    level=LOGGING_LEVEL)
logger.configure(handlers=[{"sink": sys.stderr, "level": LOGGING_LEVEL}])
示例#4
0
REDIS_PORT: int = config("REDIS_PORT", cast=int, default=6379)
REDIS_PASSWD: str = config("REDIS_PASSWD", cast=str, default='')

SECRET_KEY: Secret = config("SECRET_KEY", cast=Secret, default='welcome1')

PROJECT_NAME: str = config("PROJECT_NAME", default="FastAPI example")
ALLOWED_HOSTS: List[str] = config(
    "ALLOWED_HOSTS",
    cast=CommaSeparatedStrings,
    default="",
)
# logging configuration
LOGGING_LEVEL = logging.DEBUG if DEBUG else logging.INFO
LOGGERS = ("uvicorn.asgi", "uvicorn.access")

logging.getLogger().handlers = [InterceptHandler()]
for logger_name in LOGGERS:
    logging_logger = logging.getLogger(logger_name)
    logging_logger.handlers = [InterceptHandler(level=LOGGING_LEVEL)]
# sink可自主配置
logger.configure(handlers=[{
    "sink": sys.stdout,
    "level": LOGGING_LEVEL
}, {
    "sink": './runtime.log',
    "level": LOGGING_LEVEL
}])
# mongo db info
database_name: str = config('DATABASE_NAME', default='moop')
user_collection_name = 'user'
示例#5
0
import logging
import sys

from loguru import logger
from starlette.config import Config
from starlette.datastructures import Secret

from app.core.logging import InterceptHandler

config = Config('.env')

# ================ Project ================
API_PREFIX = '/api'
VERSION = 'v1'
PROJECT_NAME: str = config('PROJECT_NAME', cast=str)

# ================ Mysql ================
DB_TYPE: str = config('DB_TYPE')
DB_USER: str = config('DB_USERNAME')
DB_PASSWORD: Secret = config('DB_PASSWORD', cast=Secret)
DB_HOST: str = config('DB_HOST')
DB_PORT: int = config('DB_PORT', cast=int)
DATABASE: str = config('DB_DATABASE')

# ================ Logging ================
LOGGING_LEVEL: str = config('LOGGING_LEVEL', cast=str, default='INFO')
logging.basicConfig(
    handlers=[InterceptHandler(level=LOGGING_LEVEL)], level=LOGGING_LEVEL
)
logger.configure(handlers=[{'sink': sys.stderr, 'level': LOGGING_LEVEL}])