Skip to content

Commit

Permalink
all in message
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed May 29, 2024
1 parent c0d5b07 commit b6c9582
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cacholote/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Context(abc.ABC):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

@abc.abstractmethod
def info(self, *args: Any, **kwargs: Any) -> None: ...
def upload_log(self, *args: Any, **kwargs: Any) -> None: ...


class Settings(pydantic_settings.BaseSettings):
Expand Down
23 changes: 11 additions & 12 deletions cacholote/extra_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import fsspec
import fsspec.implementations.local
import pydantic
import structlog

from . import config, encode, utils

Expand Down Expand Up @@ -114,22 +113,22 @@ def _filesystem_is_local(fs: fsspec.AbstractFileSystem) -> bool:

@contextlib.contextmanager
def _logging_timer(event: str, **kwargs: Any) -> Generator[float, None, None]:
loggers: list[
structlog.BoundLogger | structlog._config.BoundLoggerLazyProxy | config.Context
] = [config.get().logger]
if (context := config.get().context) is not None:
loggers.append(context)

for logger in loggers:
logger.info(f"start {event}", **kwargs)
logger = config.get().logger
context = config.get().context
logger.info(f"start {event}", **kwargs)
if event == "upload" and context is not None:
suffix = " ".join([f"{k}: {v}" for k, v in kwargs.items()])
context.upload_log(f"start {event}. {suffix}")

tic = time.perf_counter()
yield tic
toc = time.perf_counter()
kwargs["_".join(event.split() + ["time"])] = toc - tic # elapsed time

for logger in loggers:
logger.info(f"end {event}", **kwargs)
kwargs["_".join(event.split() + ["time"])] = toc - tic # elapsed time
logger.info(f"end {event}", **kwargs)
if event == "upload" and context is not None:
suffix = " ".join([f"{k}: {v}" for k, v in kwargs.items()])
context.upload_log(f"end {event}. {suffix}")


class FileInfoModel(pydantic.BaseModel):
Expand Down

0 comments on commit b6c9582

Please sign in to comment.