Skip to content

Commit

Permalink
feat: use FastAPI logger instead of rich (#198)
Browse files Browse the repository at this point in the history
* deps: remove rich

* deps: poetry lock

* feat: use fastapi logger instead of rich
  • Loading branch information
himkt authored Jan 25, 2024
1 parent f32f52f commit 21aaadb
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 171 deletions.
277 changes: 120 additions & 157 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ kytea = {version = "^0.1.8", optional = true}
nagisa = {version = "^0.2.7", optional = true}
natto-py = {version = "^1.0.0", optional = true}
pydata-sphinx-theme = {version = "^0.10.1", optional = true}
rich = {version = "^13.7.0", optional = true}
requests = "<3.0.0"
sentencepiece = {version = "^0.1.85", optional = true}
sudachipy = {version = "^0.5.0", optional = true}
Expand All @@ -36,8 +35,8 @@ sudachi = ["sudachipy", "sudachidict-core"]
nagisa = ["nagisa"]
sentencepiece = ["sentencepiece"]
remote = ["boto3"]
server = ["fastapi", "uvicorn", "rich"]
all = ["janome", "natto-py", "kytea", "sudachipy", "sudachidict-core", "nagisa", "sentencepiece", "boto3", "fastapi", "uvicorn", "rich"]
server = ["fastapi", "uvicorn"]
all = ["janome", "natto-py", "kytea", "sudachipy", "sudachidict-core", "nagisa", "sentencepiece", "boto3", "fastapi", "uvicorn"]
docs = ["sphinx", "pydata-sphinx-theme"]

[tool.poetry.group.test.dependencies]
Expand Down
3 changes: 1 addition & 2 deletions src/konoha/api/server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging

from fastapi import FastAPI
from rich.logging import RichHandler

from konoha.api.v1 import tokenization
from konoha.api.v1 import batch_tokenization


FORMAT = "%(message)s"
logging.basicConfig(level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()])
logging.basicConfig(level="INFO")


def create_app() -> FastAPI:
Expand Down
6 changes: 3 additions & 3 deletions src/konoha/api/v1/batch_tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TokenizeParameter(BaseModel):


router = APIRouter()
logger = logging.getLogger(__file__)
logger = logging.getLogger("uvicorn.app.konoha.api.v1.batch_tokenization")


def generate_cache_key(params):
Expand All @@ -37,10 +37,10 @@ async def batch_tokenize(params: TokenizeParameter, request: Request):

cache_key = generate_cache_key(params)
if cache_key in request.app.state.cache:
logging.info(f"Hit cache: {cache_key}")
logger.info(f"Hit cache: {cache_key}")
tokenizer = request.app.state.cache[cache_key]
else:
logging.info(f"Create tokenizer: {cache_key}")
logger.info(f"Create tokenizer: {cache_key}")
try:
tokenizer = WordTokenizer(
tokenizer=params.tokenizer,
Expand Down
6 changes: 3 additions & 3 deletions src/konoha/api/v1/tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TokenizeParameter(BaseModel):


router = APIRouter()
logger = logging.getLogger(__file__)
logger = logging.getLogger("uvicorn.app.konoha.api.v1.tokenization")


def generate_cache_key(params):
Expand All @@ -44,10 +44,10 @@ async def tokenize(params: TokenizeParameter, request: Request):

cache_key = generate_cache_key(params)
if cache_key in request.app.state.cache:
logging.info(f"Hit cache: {cache_key}")
logger.info(f"Hit cache: {cache_key}")
tokenizer = request.app.state.cache[cache_key]
else:
logging.info(f"Create tokenizer: {cache_key}")
logger.info(f"Create tokenizer: {cache_key}")
try:
tokenizer = WordTokenizer(
tokenizer=params.tokenizer,
Expand Down
6 changes: 3 additions & 3 deletions src/konoha/data/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RST = "\033[0;0m"


logger = logging.getLogger(__name__)
logger = logging.getLogger("uvicorn.app.konoha.data.resource")


class Resource:
Expand Down Expand Up @@ -65,10 +65,10 @@ def download_from_s3(self, path: str) -> str:
logger.info(f"Downloading {obj.key}")
download_path = os.path.join(resource_dir, obj.key)
bucket.download_file(obj.key, download_path)
logging.info(f"Downloaded to {download_path}")
logger.info(f"Downloaded to {download_path}")

dest_dir = os.path.join(resource_dir, prefix)
logging.info(f"Downloaded to {dest_dir}")
logger.info(f"Downloaded to {dest_dir}")
return dest_dir

@property
Expand Down

0 comments on commit 21aaadb

Please sign in to comment.