Utilisation du logger global dans app et db
This commit is contained in:
+1
-11
@@ -1,4 +1,3 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
@@ -8,15 +7,13 @@ from dotenv import load_dotenv
|
||||
from flask import Response
|
||||
|
||||
from src.cache import cache
|
||||
from src.utils import DEVELOPMENT
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# if os.getenv("PYTEST_CURRENT_TEST"):
|
||||
# os.environ["DATA_FILE_PARQUET_PATH"]
|
||||
|
||||
# TODO: Importer LOGGER et DEVELOPMENT depuis utils.init
|
||||
DEVELOPMENT = os.getenv("DEVELOPMENT", "").lower() == "true"
|
||||
|
||||
META_TAGS = [
|
||||
{"name": "viewport", "content": "width=device-width, initial-scale=1"},
|
||||
{
|
||||
@@ -76,13 +73,6 @@ def sitemap():
|
||||
return Response(xml, mimetype="text/xml")
|
||||
|
||||
|
||||
logger = logging.getLogger("decp.info")
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s %(levelname)-8s %(message)s",
|
||||
level=logging.INFO,
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
|
||||
with open("./pyproject.toml", "rb") as f:
|
||||
pyproject = tomllib.load(f)
|
||||
version = "v" + pyproject["project"]["version"]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fcntl
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
@@ -9,8 +8,7 @@ import polars as pl
|
||||
import polars.selectors as cs
|
||||
from polars.exceptions import ComputeError
|
||||
|
||||
# TODO: Importer le logger depuis utils
|
||||
LOGGER = logging.getLogger("decp.info")
|
||||
from src.utils import logger
|
||||
|
||||
|
||||
def should_rebuild(db_path: Path, parquet_path: Path) -> bool:
|
||||
@@ -34,7 +32,7 @@ def _load_source_frame(parquet_path: Path) -> pl.DataFrame:
|
||||
try:
|
||||
lff: pl.LazyFrame = pl.scan_parquet(str(parquet_path))
|
||||
except ComputeError:
|
||||
LOGGER.info("Lecture du parquet échouée, nouvelle tentative dans 10s...")
|
||||
logger.info("Lecture du parquet échouée, nouvelle tentative dans 10s...")
|
||||
sleep(10)
|
||||
lff = pl.scan_parquet(str(parquet_path))
|
||||
|
||||
@@ -72,7 +70,7 @@ def build_database(db_path: Path, parquet_path: Path) -> None:
|
||||
if tmp_path.exists():
|
||||
tmp_path.unlink()
|
||||
|
||||
LOGGER.info(f"Construction de la base DuckDB à partir de {parquet_path}...")
|
||||
logger.info(f"Construction de la base DuckDB à partir de {parquet_path}...")
|
||||
frame = _load_source_frame(parquet_path)
|
||||
|
||||
# Write transformed frame as parquet so DuckDB can read it natively
|
||||
@@ -108,7 +106,7 @@ def build_database(db_path: Path, parquet_path: Path) -> None:
|
||||
staging_parquet.unlink()
|
||||
|
||||
os.replace(tmp_path, db_path)
|
||||
LOGGER.info(f"Base DuckDB construite : {db_path}")
|
||||
logger.info(f"Base DuckDB construite : {db_path}")
|
||||
|
||||
|
||||
def _resolve_db_path() -> Path:
|
||||
@@ -127,6 +125,8 @@ def _ensure_database() -> Path:
|
||||
fcntl.flock(lock_fd, fcntl.LOCK_EX)
|
||||
if should_rebuild(db_path, parquet_path):
|
||||
build_database(db_path, parquet_path)
|
||||
else:
|
||||
logger.info("Base de données déjà disponible et à jour.")
|
||||
return db_path
|
||||
|
||||
|
||||
|
||||
@@ -13,5 +13,7 @@ if DEVELOPMENT:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
DOMAIN_NAME = (
|
||||
"test.decp.info" if os.getenv("DEVELOPMENT").lower() == "true" else "decp.info"
|
||||
"test.decp.info"
|
||||
if os.getenv("DEVELOPMENT", "False").lower() == "true"
|
||||
else "decp.info"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user