Skip to content

Commit

Permalink
Fix: logging formatter costomize style
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanHeng committed Apr 18, 2024
1 parent cc351d2 commit 8b93580
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.38.0'
VERSION = '0.39.0'
DESCRIPTION = 'Machine Learning project startup utilities'
LONG_DESCRIPTION = 'My commonly used utilities for machine learning projects'

Expand All @@ -13,11 +13,11 @@
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
url='https://github.com/StefanHeng/stef-util',
download_url='https://github.com/StefanHeng/stef-util/archive/refs/tags/v0.38.0.tar.gz',
download_url='https://github.com/StefanHeng/stef-util/archive/refs/tags/v0.39.0.tar.gz',
packages=find_packages(),
include_package_data=True,
install_requires=[
'sty', 'colorama', 'pygments',
'click', # for ANSI styling
'numpy', 'pandas',
'tqdm', 'icecream'
],
Expand Down
19 changes: 11 additions & 8 deletions stefutil/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,12 @@ def __init__(self, with_color=True, style_time: Dict[str, Any] = None, style_sep
self.with_color = with_color

if ANSI_BACKEND == 'click':
time_style_args = MyFormatter.time.copy()
time_style_args.update(style_time or dict())
color_time = s.s(MyFormatter.KW_TIME, **time_style_args) + s.s('|', **MyFormatter.sep)
self.time_style_args = MyFormatter.time.copy()
self.time_style_args.update(style_time or dict())
self.sep_style_args = MyFormatter.sep.copy()
self.sep_style_args.update(style_sep or dict())

color_time = s.s(MyFormatter.KW_TIME, **self.time_style_args) + s.s('|', **self.sep_style_args)
else:
assert ANSI_BACKEND == 'colorama'
if style_time:
Expand All @@ -606,7 +609,7 @@ def __init__(self, with_color=True, style_time: Dict[str, Any] = None, style_sep
def args2fmt(args_):
if self.with_color:
if ANSI_BACKEND == 'click':
return color_time + self.fmt_meta(*args_) + s.s(': ', **MyFormatter.sep) + MyFormatter.KW_MSG + _ansi_reset_all
return color_time + self.fmt_meta(*args_) + s.s(': ', **self.sep_style_args) + MyFormatter.KW_MSG + _ansi_reset_all
else:
assert ANSI_BACKEND == 'colorama'
return color_time + self.fmt_meta(*args_) + f'{c_sep}: {reset}{MyFormatter.KW_MSG}' + reset
Expand All @@ -622,10 +625,10 @@ def fmt_meta(self, meta_abv, meta_style: Union[str, Dict[str, Any]] = None):
if self.with_color:
if ANSI_BACKEND == 'click':
return '[' + s.s(MyFormatter.KW_NAME, fg='m') + ']' \
+ s.s('::', **MyFormatter.sep) + s.s(MyFormatter.KW_FUNC_NM, fg='m') \
+ s.s('::', **MyFormatter.sep) + s.s(MyFormatter.KW_FNM, fg='m') \
+ s.s(':', **MyFormatter.sep) + s.s(MyFormatter.KW_LINENO, fg='m') \
+ s.s(':', **MyFormatter.sep) + s.s(meta_abv, **meta_style)
+ s.s('::', **self.sep_style_args) + s.s(MyFormatter.KW_FUNC_NM, fg='m') \
+ s.s('::', **self.sep_style_args) + s.s(MyFormatter.KW_FNM, fg='m') \
+ s.s(':', **self.sep_style_args) + s.s(MyFormatter.KW_LINENO, fg='m') \
+ s.s(':', **self.sep_style_args) + s.s(meta_abv, **meta_style)
else:
assert ANSI_BACKEND == 'colorama'
return f'[{MyFormatter.purple}{MyFormatter.KW_NAME}{MyFormatter.RESET}]' \
Expand Down

0 comments on commit 8b93580

Please sign in to comment.