Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use recommended dictConfig for logger configuration #83

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
entry: bash -c "poetry run mypy ."
language: system
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
rev: v0.3.3
hooks:
- id: ruff
- id: ruff-format
Expand Down
6 changes: 2 additions & 4 deletions ixmp4/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class PlatformInfo(pydantic.BaseModel):


class Config(Protocol):
def list_platforms(self) -> list[PlatformInfo]:
...
def list_platforms(self) -> list[PlatformInfo]: ...

def get_platform(self, key: str) -> PlatformInfo:
...
def get_platform(self, key: str) -> PlatformInfo: ...
24 changes: 0 additions & 24 deletions ixmp4/conf/logging/debug.conf

This file was deleted.

21 changes: 21 additions & 0 deletions ixmp4/conf/logging/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters":{
"generic": {
"format": "[%(levelname)s] %(asctime)s - %(name)s: %(message)s",
"datefmt": "%H:%M:%S"
}
},
"root": {
"level": "DEBUG",
"handlers": ["console"]
},
"handlers":{
"console":{
"class": "logging.StreamHandler",
"level": "NOTSET",
"formatter": "generic"
}
}
}
24 changes: 0 additions & 24 deletions ixmp4/conf/logging/development.conf

This file was deleted.

21 changes: 21 additions & 0 deletions ixmp4/conf/logging/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters":{
"generic":{
"format": "[%(levelname)s] %(asctime)s - %(name)s: %(message)s",
"datefmt": "%H:%M:%S"
}
},
"root":{
"level": "INFO",
"handlers": ["console"]
},
"handlers":{
"console":{
"class": "logging.StreamHandler",
"level": "NOTSET",
"formatter": "generic"
}
}
}
glatterf42 marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 0 additions & 30 deletions ixmp4/conf/logging/production.conf

This file was deleted.

23 changes: 23 additions & 0 deletions ixmp4/conf/logging/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"generic": {
"format": "[%(levelname)s] %(asctime)s - %(name)s: %(message)s",
"datefmt": "%H:%M:%S"
}
},
"loggers": {
"ixmp4": {
"level": "INFO",
"handlers": ["console"]
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "NOTSET",
"formatter": "generic"
}
}
}
73 changes: 0 additions & 73 deletions ixmp4/conf/logging/server.conf

This file was deleted.

71 changes: 71 additions & 0 deletions ixmp4/conf/logging/server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters":{
"generic": {
"format": "[%(levelname)s] %(asctime)s - %(name)s: %(message)s",
"datefmt": "%H:%M:%S"
}
},
"loggers": {
"fastapi": {
"level": "NOTSET",
"handlers": ["debug","error","console"]
},
"httpx": {
"level": "NOTSET",
"handlers": ["debug","error"]
},
"sqlalchemy": {
"level": "NOTSET",
"handlers": ["debug","error"]
},
"uvicorn": {
"level": "NOTSET",
"handlers": ["debug","error","console"]
},
"uvicorn.access": {
"level": "NOTSET",
"handlers": ["access"]
},
"watchfiles.main": {
"level": "ERROR",
"handlers": ["error","debug"]
}
},
"handlers": {
"access": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "generic",
"filename": "os.getenv('IXMP4_ACCESS_LOG')",
"mode": "a",
"maxBytes": 250000
},
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "generic"
},
"debug": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "generic",
"filename": "os.getenv('IXMP4_DEBUG_LOG')",
"mode": "a",
"maxBytes": 250000
},
"error": {
"class": "logging.handlers.RotatingFileHandler",
"level": "WARN",
"formatter": "generic",
"filename": "os.getenv('IXMP4_ERROR_LOG')",
"mode": "a",
"maxBytes": 250000
}
},
"root": {
"level": "NOTSET",
"handlers": ["debug","error"]
}
}
glatterf42 marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 8 additions & 5 deletions ixmp4/conf/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import logging.config
import os
Expand All @@ -22,9 +23,9 @@


class Settings(BaseSettings):
mode: Literal["production"] | Literal["development"] | Literal[
"debug"
] = "production"
mode: Literal["production"] | Literal["development"] | Literal["debug"] = (
"production"
)
storage_directory: Path = Field(
"~/.local/share/ixmp4/", json_schema_extra={"env": "ixmp4_dir"}
)
Expand Down Expand Up @@ -144,8 +145,10 @@ def configure_logging(self, config: str):
os.environ.setdefault("IXMP4_DEBUG_LOG", str(debug_file.absolute()))
os.environ.setdefault("IXMP4_ERROR_LOG", str(error_file.absolute()))

logging_config = here / f"logging/{config}.conf"
logging.config.fileConfig(logging_config, disable_existing_loggers=False)
logging_config = here / f"logging/{config}.json"
with open(logging_config, "r") as file:
glatterf42 marked this conversation as resolved.
Show resolved Hide resolved
config_dict = json.load(file)
logging.config.dictConfig(config_dict)

def check_credentials(self):
if self.default_credentials is not None:
Expand Down
Loading
Loading