Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ To run tests, run the following command:
pip install -r ./requirements.test.txt

# Run tests:
python -m pytest -sv
python -m pytest -v
```

## Environment Variables
Expand Down
3 changes: 2 additions & 1 deletion beans_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from .schemas import LoggerConfigPM
from ._base import Logger, logger, LoggerLoader
from .schemas import LoggerConfigPM
from ._const import WarnEnum
from .__version__ import __version__
7 changes: 3 additions & 4 deletions beans_logging/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

## Third-party libraries
import yaml
from pydantic import validate_call
from loguru._logger import Logger
from loguru import logger
from loguru._logger import Logger
from pydantic import validate_call

## Internal modules
from ._utils import create_dir, deep_merge
Expand Down Expand Up @@ -170,7 +170,6 @@ def update_config(self, config: Union[LoggerConfigPM, Dict[str, Any]]):
if isinstance(config, dict):
_config_dict = self.config.model_dump()
_merged_dict = deep_merge(_config_dict, config)
print(_merged_dict)
try:
self.config = LoggerConfigPM(**_merged_dict)
except Exception:
Expand Down Expand Up @@ -470,7 +469,7 @@ def add_custom_handler(self, handler_name: str, **kwargs) -> int:
_log_path = _log_path.format(app_name=self.config.app_name)

_logs_dir, _ = os.path.split(_log_path)
create_dir(create_dir=_logs_dir, warn_mode="DEBUG")
create_dir(create_dir=_logs_dir)
kwargs["sink"] = _log_path

if "format" not in kwargs:
Expand Down
10 changes: 10 additions & 0 deletions beans_logging/_const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from enum import Enum


class WarnEnum(str, Enum):
RAISE = "RAISE"
LOG = "LOG"
DEBUG = "DEBUG"
IGNORE = "IGNORE"
17 changes: 7 additions & 10 deletions beans_logging/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
import copy
import errno

# import logging

from pydantic import validate_call
from loguru import logger
from pydantic import validate_call

# logger = logging.getLogger(__name__)
from ._const import WarnEnum


@validate_call
def create_dir(create_dir: str, warn_mode: str = "DEBUG"):
def create_dir(create_dir: str, warn_mode: WarnEnum = WarnEnum.DEBUG):
"""Create directory if `create_dir` doesn't exist.

Args:
create_dir (str, required): Create directory path.
warn_mode (str, optional): Warning message mode, for example: 'LOG', 'DEBUG', 'QUIET'. Defaults to "QUIET".
"""

warn_mode = warn_mode.strip().upper()
if not os.path.isdir(create_dir):
try:
_message = f"Creaing '{create_dir}' directory..."
if warn_mode == "LOG":
if warn_mode == WarnEnum.LOG:
logger.info(_message)
elif warn_mode == "DEBUG":
elif warn_mode == WarnEnum.DEBUG:
logger.debug(_message)

os.makedirs(create_dir)
Expand All @@ -39,9 +36,9 @@ def create_dir(create_dir: str, warn_mode: str = "DEBUG"):
raise

_message = f"Successfully created '{create_dir}' directory."
if warn_mode == "LOG":
if warn_mode == WarnEnum.LOG:
logger.success(_message)
elif warn_mode == "DEBUG":
elif warn_mode == WarnEnum.DEBUG:
logger.debug(_message)


Expand Down
4 changes: 2 additions & 2 deletions beans_logging/fastapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from ._middlewares import HttpAccessLogMiddleware
from ._handlers import add_http_file_handler, add_http_file_json_handler
from ._filters import use_http_filter
from ._formats import http_file_format, http_file_json_format
from ._handlers import add_http_file_handler, add_http_file_json_handler
from ._middlewares import HttpAccessLogMiddleware
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PyYAML>=6.0.1,<7.0
pydantic>=2.1.1,<3.0.0
loguru>=0.7.1,<1.0.0
loguru>=0.7.2,<1.0.0
4 changes: 2 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ main()
fi

if [ "${_IS_VERBOSE}" == true ]; then
_verbose_param="-vv"
_verbose_param="-svv"
fi

echoInfo "Running test..."
# shellcheck disable=SC2086
python -m pytest -sv ${_coverage_param} ${_logging_param} ${_verbose_param} || exit 2
python -m pytest -v ${_coverage_param} ${_logging_param} ${_verbose_param} || exit 2
echoOk "Done."
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
install_requires=[
"PyYAML>=6.0,<7.0",
"pydantic>=2.1.1,<3.0.0",
"loguru>=0.7.1,<1.0.0",
"loguru>=0.7.2,<1.0.0",
],
classifiers=[
"Development Status :: 4 - Beta",
Expand Down