Skip to content

Commit

Permalink
Merge pull request #9 from opendilab/dev/fallback
Browse files Browse the repository at this point in the history
dev(hansbug): add fallback for rick logging
  • Loading branch information
HansBug authored Jan 17, 2024
2 parents fc9007e + 106e72e commit 0b68b26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 10 additions & 1 deletion ditk/logging/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
from logging import LogRecord

import rich.errors

from .base import _LogLevelType
from .rich import _create_rich_handler
from .stream import _create_stream_handler
Expand Down Expand Up @@ -43,4 +45,11 @@ def emit(self, record: LogRecord) -> None:
If ``DISABLE_RICH`` environment variable is set to non-empty, this method is equal to \
:meth:`logging.StreamHandler.emit`, otherwise equals to :meth:`rich.logging.RichHandler.emit`.
"""
return self._get_current_handler().emit(record)
try:
return self._get_current_handler().emit(record)
except rich.errors.ConsoleError:
if _use_rich():
stream_handler = _create_stream_handler(self.use_stdout, self.level)
return stream_handler.emit(record)
else:
raise
10 changes: 5 additions & 5 deletions requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Jinja2~=3.0.0
sphinx~=3.2.0
sphinx_rtd_theme~=0.4.3
enum_tools
Jinja2>=3.0.0
sphinx>=3.2.0
sphinx_rtd_theme>=0.4.3
enum_tools~=0.9.0
sphinx-toolbox
plantumlcli>=0.0.2
packaging
sphinx-multiversion~=0.2.4
sphinx-multiversion>=0.2.4
where~=1.0.2
easydict>=1.7,<2

0 comments on commit 0b68b26

Please sign in to comment.