Skip to content

Commit

Permalink
Config tos client log to align tosfs
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 10, 2024
1 parent 7d0e2f3 commit 85197c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions tosfs/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 12 additions & 1 deletion tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 85197c0

Please sign in to comment.