Skip to content

Commit

Permalink
[Refactor] Enhance logging with bold and colored headers for better r…
Browse files Browse the repository at this point in the history
…eadability
  • Loading branch information
CVHub520 committed Sep 19, 2024
1 parent 995cf04 commit 73a4288
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
26 changes: 17 additions & 9 deletions anylabeling/checks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from app_info import __appname__, __version__, __preferred_device__
from views.labeling.utils.general import collect_system_info
import logging
import pprint
from app_info import __appname__, __version__, __preferred_device__
from views.labeling.utils.general import (
collect_system_info,
format_bold,
format_color,
indent_text,
)

logging.basicConfig(level=logging.INFO, format='%(message)s')
logger = logging.getLogger(__name__)

if __name__ == "__main__":
app_info = {
Expand All @@ -9,13 +18,12 @@
"Device": __preferred_device__,
}
system_info, pkg_info = collect_system_info()
pp = pprint.PrettyPrinter(indent=2)

print("Application Information:")
pp.pprint(app_info)
logger.info(format_color(format_bold("Application Information:"), '36'))
logger.info(indent_text(pprint.pformat(app_info)))

print("\nSystem Information:")
pp.pprint(system_info)
logger.info(format_color(format_bold("\nSystem Information:"), '36'))
logger.info(indent_text(pprint.pformat(system_info)))

print("\nPackage Information:")
pp.pprint(pkg_info)
logger.info(format_color(format_bold("\nPackage Information:"), '36'))
logger.info(indent_text(pprint.pformat(pkg_info)))
13 changes: 13 additions & 0 deletions anylabeling/views/labeling/utils/general.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import re
import textwrap
import platform
import subprocess
from importlib_metadata import version as get_package_version


def format_bold(text):
return f"\033[1m{text}\033[0m"


def format_color(text, color_code):
return f"\033[{color_code}m{text}\033[0m"


def hex_to_rgb(hex_color):
hex_color = hex_color.lstrip("#")
return tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4))


def indent_text(text, indent=4):
return textwrap.indent(text, ' ' * indent)


def is_chinese(s="人工智能"):
# Is string composed of any Chinese characters?
return bool(re.search("[\u4e00-\u9fff]", str(s)))
Expand Down

0 comments on commit 73a4288

Please sign in to comment.