From 85197c0ba86893b70baa255ed0d9cf94d22be1fd Mon Sep 17 00:00:00 2001 From: yanghua Date: Tue, 10 Sep 2024 11:55:24 +0800 Subject: [PATCH] Config tos client log to align tosfs --- tosfs/consts.py | 1 + tosfs/core.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tosfs/consts.py b/tosfs/consts.py index 31ef130..207a363 100644 --- a/tosfs/consts.py +++ b/tosfs/consts.py @@ -43,3 +43,4 @@ # environment variable names ENV_NAME_TOSFS_LOGGING_LEVEL = "TOSFS_LOGGING_LEVEL" +TOSFS_LOG_FORMAT = "%(asctime)s %(name)s [%(levelname)s] %(funcName)s : %(message)s" diff --git a/tosfs/core.py b/tosfs/core.py index 044d98f..674895c 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -45,7 +45,7 @@ PART_MAX_SIZE, PUT_OBJECT_OPERATION_SMALL_FILE_THRESHOLD, RETRY_NUM, - TOS_SERVER_RESPONSE_CODE_NOT_FOUND, + TOS_SERVER_RESPONSE_CODE_NOT_FOUND, TOSFS_LOG_FORMAT, ) from tosfs.exceptions import TosfsError from tosfs.fsspec_utils import glob_translate @@ -61,6 +61,16 @@ def setup_logging() -> None: level=os.environ.get(ENV_NAME_TOSFS_LOGGING_LEVEL, "INFO"), ) + formatter = logging.Formatter(TOSFS_LOG_FORMAT) + for handler in logger.handlers: + handler.setFormatter(formatter) + + # set and config tos client's logger + tos.set_logger(name="tosclient", + level=os.environ.get(ENV_NAME_TOSFS_LOGGING_LEVEL, "INFO"), + log_handler=logging.StreamHandler(), + format_string=TOSFS_LOG_FORMAT) + setup_logging() @@ -1663,6 +1673,7 @@ def _listdir( raise TosfsError(f"Tosfs failed with unknown error: {e}") from e def _rm(self, path: str) -> None: + logger.info("Removing path: %s", path) bucket, key, _ = self._split_path(path) if path.endswith("/") or self.isdir(path):