Skip to content

Commit

Permalink
Init logging for tosfs
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Aug 14, 2024
1 parent cdadad5 commit 00a7eed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,29 @@
"""
The core module of TOSFS.
"""
import logging
import os

from fsspec.utils import setup_logging as setup_logger

# environment variable names
ENV_NAME_TOSFS_LOGGING_LEVEL = "TOSFS_LOGGING_LEVEL"

logger = logging.getLogger("tosfs")


def setup_logging():
"""
Set up the logging configuration for TOSFS.
"""
setup_logger(
logger=logger,
level=os.environ.get(ENV_NAME_TOSFS_LOGGING_LEVEL, "INFO"),
)


setup_logging()

logger.warning(
"The tosfs's log level is set to be %s", logging.getLevelName(logger.level)
)
30 changes: 30 additions & 0 deletions tosfs/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ByteDance Volcengine EMR, Copyright 2022.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os

from tosfs.core import ENV_NAME_TOSFS_LOGGING_LEVEL, setup_logging


def test_logging_level_debug():
# Set the environment variable to DEBUG
os.environ[ENV_NAME_TOSFS_LOGGING_LEVEL] = "DEBUG"

# Re-setup logging to apply the new environment variable
setup_logging()

# Get the logger and check its level
logger = logging.getLogger("tosfs")
assert logger.level == logging.DEBUG

0 comments on commit 00a7eed

Please sign in to comment.