Skip to content

Commit

Permalink
Add logger (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 authored May 29, 2024
1 parent ccfca74 commit f7e63ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions ibis-server/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self):
load_dotenv(override=True)
self.wren_engine_endpoint = os.getenv('WREN_ENGINE_ENDPOINT')
self.validate_wren_engine_endpoint(self.wren_engine_endpoint)
self.log_level = os.getenv('LOG_LEVEL', 'INFO')

@staticmethod
def validate_wren_engine_endpoint(endpoint):
Expand Down
9 changes: 9 additions & 0 deletions ibis-server/app/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging

from app.config import get_config

logging.basicConfig(level=get_config().log_level)


def get_logger(name):
return logging.getLogger(name)
10 changes: 5 additions & 5 deletions ibis-server/app/routers/ibis.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging
from json import loads

from fastapi import APIRouter
from fastapi import APIRouter, Request

from app.logger import get_logger
from app.mdl.rewriter import Rewriter
from app.model.data_source import DataSource
from app.model.dto import IbisDTO

logger = logging.getLogger()
logger = get_logger(__name__)
router = APIRouter(prefix="/v2/ibis")


Expand All @@ -19,7 +19,7 @@ def to_json(df) -> dict:


@router.post("/{data_source}/query")
def query(data_source: DataSource, dto: IbisDTO) -> dict:
logger.debug(f'DTO: {dto}')
def query(data_source: DataSource, dto: IbisDTO, request: Request) -> dict:
logger.debug(f'{request.method} {request.url.path}, DTO: {dto}')
rewritten_sql = Rewriter.rewrite(dto.manifest_str, dto.sql)
return to_json(data_source.get_connection(dto.connection_info).sql(rewritten_sql, dialect='trino').to_pandas())

0 comments on commit f7e63ba

Please sign in to comment.