Skip to content

Commit

Permalink
try to use rich package for more structured console output!
Browse files Browse the repository at this point in the history
  • Loading branch information
lf-zhao committed Apr 23, 2024
1 parent bf4000d commit 19d9d53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions predicators/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def create_arg_parser(env_required: bool = True,
parser.add_argument("--experiment_id", default="", type=str)
parser.add_argument("--load_experiment_id", default="", type=str)
parser.add_argument("--log_file", default="", type=str)
parser.add_argument("--log_rich", default="true", type=str)
parser.add_argument("--use_gui", action="store_true")
parser.add_argument('--debug',
action="store_const",
Expand Down
10 changes: 8 additions & 2 deletions predicators/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ def main() -> None:
args = utils.parse_args()
utils.update_config(args)
str_args = " ".join(sys.argv)
# Log to stderr.
handlers: List[logging.Handler] = [logging.StreamHandler()]
# Log to stderr or use `rich` package for more structured output.
handlers: List[logging.Handler] = []
if CFG.log_rich:
from rich.logging import RichHandler
handlers.append(RichHandler())
else:
handlers.append(logging.StreamHandler())

if CFG.log_file:
handlers.append(logging.FileHandler(CFG.log_file, mode='w'))
logging.basicConfig(level=CFG.loglevel,
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"opencv-python == 4.7.0.72",
"pg3@git+https://github.com/tomsilver/pg3.git",
"gym_sokoban@git+https://github.com/Learning-and-Intelligent-Systems/gym-sokoban.git", # pylint: disable=line-too-long
"pbrspot@git+https://github.com/NishanthJKumar/pbrspot.git"
"pbrspot@git+https://github.com/NishanthJKumar/pbrspot.git",
"rich",
],
include_package_data=True,
extras_require={
Expand Down

0 comments on commit 19d9d53

Please sign in to comment.