def get_logger(name: str, log_level=logging.INFO): logger = logging.getLogger(name) if not logger.handlers: logger.setLevel(log_level) ch = logging.StreamHandler() ch.setFormatter(DefaultFormatter(fmt="%(levelprefix)s %(message)s")) logger.addHandler(ch) return logger
# Handler CONSOLE_HANDLER = logging.StreamHandler(sys.stdout) try: from optimade.server.config import CONFIG CONSOLE_HANDLER.setLevel(CONFIG.log_level.value.upper()) if CONFIG.debug: CONSOLE_HANDLER.setLevel(logging.DEBUG) except ImportError: CONSOLE_HANDLER.setLevel(os.getenv("OPTIMADE_LOG_LEVEL", "INFO").upper()) # Formatter CONSOLE_FORMATTER = DefaultFormatter("%(levelprefix)s [%(name)s] %(message)s") CONSOLE_HANDLER.setFormatter(CONSOLE_FORMATTER) # Add handler to LOGGER LOGGER.addHandler(CONSOLE_HANDLER) # Save a file with all messages (DEBUG level) try: from optimade.server.config import CONFIG LOGS_DIR = CONFIG.log_dir except ImportError: LOGS_DIR = Path(os.getenv("OPTIMADE_LOG_DIR", "/var/log/optimade/")).resolve() try:
MessageHandlerMap, ) from fastmsa.uow import AbstractUnitOfWork MESSAGE_HANDLERS: MessageHandlerMap = defaultdict(list) E = TypeVar("E", bound=Event) C = TypeVar("C", bound=Command) M = TypeVar("M", bound=Message) F = TypeVar("F", bound=Callable[..., Any]) T = TypeVar("T") logger = logging.getLogger("fastmsa.core.event") logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setFormatter(DefaultFormatter()) logger.addHandler(ch) class MessageBus(AbstractMessageHandler): def __init__( self, handlers: MessageHandlerMap, msa: Optional[AbstractFastMSA] = None, uow: Optional[AbstractUnitOfWork] = None, pubsub: Optional[AbstractPubsubClient] = None, broker: Optional[AbstractMessageBroker] = None, ): self.handlers = handlers self._msa = msa self.uow, self.broker, self.pubsub = uow, broker, pubsub
HttpUrl, PostgresDsn, RedisDsn, SecretStr, validator, ) from pydantic.tools import parse_obj_as from uvicorn.logging import DefaultFormatter project_root = Path(__file__).resolve().parents[1] uvicorn_logger = logging.getLogger("uvicorn.access") logger = logging.getLogger("fgoapi") console_handler = logging.StreamHandler() console_handler.setFormatter( DefaultFormatter("%(levelprefix)s %(name)s: %(message)s")) logger.addHandler(console_handler) logger.setLevel(uvicorn_logger.level) # pylint: disable=no-self-argument, no-self-use class Settings(BaseSettings): na_gamedata: DirectoryPath jp_gamedata: DirectoryPath rayshift_api_url: HttpUrl = parse_obj_as(HttpUrl, "https://rayshift.io/api/v1/") quest_cache_length: int = 3600 write_postgres_data: bool = True write_redis_data: bool = True asset_url: HttpUrl = parse_obj_as( HttpUrl, "https://assets.atlasacademy.io/GameData/")
async def setup_logging(): handler = logging.StreamHandler() formatter = DefaultFormatter("%(levelprefix)s %(asctime)s %(name)s %(message)s") handler.setFormatter(formatter) logger.setLevel(logging.DEBUG) logger.addHandler(handler)
import logging from uvicorn.logging import DefaultFormatter from app import config ch = logging.StreamHandler() log_format = '%(asctime)s - %(levelprefix)s %(name)s: %(message)s' formatter = DefaultFormatter(fmt=log_format) ch.setFormatter(formatter) logging.basicConfig( level=config.LOG_LEVEL, #format='%(asctime)s - %(levelprefix)s %(name)s: %(message)s', handlers=[ch]) logging.getLogger('prethink').setLevel(logging.WARNING) def get_logger(name=__name__, level='DEBUG'): logger = logging.getLogger(name) return logger