Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Make copy of logging utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarbuzzi committed May 29, 2024
1 parent 32ab964 commit 21fa864
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion neuralmagic/benchmarks/run_benchmark_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import requests

from ...tests.utils.logging import log_banner, make_logger
from ..tools.call_cmd import call_cmd
from ..tools.logging import log_banner, make_logger
from .common import (benchmark_configs, download_model,
max_model_length_from_model_id, script_args_to_cla)
from .scripts.common import num_available_gpus, warmup_server
Expand Down
33 changes: 33 additions & 0 deletions neuralmagic/tools/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging


def make_logger(name: str) -> logging.Logger:
"""Create a base logger"""

logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(name)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
return logger


def log_banner(logger: logging.Logger,
label: str,
body: str,
level: int = logging.INFO):
"""
Log a message in the "banner"-style format.
:param logger: Instance of "logging.Logger" to use
:param label: Label for the top of the banner
:param body: Body content inside the banner
:param level: Logging level to use (default: INFO)
"""

banner = f"==== {label} ====\n{body}\n===="
logger.log(level, "\n%s", banner)

0 comments on commit 21fa864

Please sign in to comment.