Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with logging scope (#2901) #bug #2901

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
32 changes: 5 additions & 27 deletions openpnm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,13 @@

def _get_version():
from openpnm.__version__ import __version__ as ver

suffix = ".dev0"
if ver.endswith(suffix):
ver = ver[:-len(suffix)]
ver = ver[: -len(suffix)]
return ver


def _setup_logger():
import os
import logging
# You can add info to the logger message by inserting the desired %(item)
# For a list of available items see:
# https://docs.python.org/3/library/logging.html#logrecord-attributes
# NOTE: If the calling locations appears as 'root' it's because the logger
# was not given a name in a file somewhere. A good option is __name__.

try:
terminal_width = os.get_terminal_size().columns
except OSError:
terminal_width = 60
column_width = terminal_width if terminal_width < 60 else 60

log_format = \
'-' * column_width + '\n\
- %(levelname)-7s: %(message)s \n\
- SOURCE : %(name)s.%(funcName)s \n\
- TIME : %(asctime)s\
\n' + '-' * column_width

logging.basicConfig(level=logging.WARNING, format=log_format)
del log_format


def _setup_logger_rich():
import logging
from rich.logging import RichHandler
Expand All @@ -57,3 +32,6 @@ def _setup_logger_rich():
logging.basicConfig(
format=FORMAT, datefmt="[%X]", handlers=[RichHandler(rich_tracebacks=True)]
)


_setup_logger_rich()
Loading