Skip to content

Commit

Permalink
log: Use the same format when we're in INFO / DEBUG mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jongy committed Nov 9, 2023
1 parent cfd9ec1 commit c2c9b91
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions gprofiler/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NO_SERVER_EXTRA_KEY = "no_extra_to_server"
CYCLE_ID_KEY = "cycle_id"
LOGGER_NAME_RE = re.compile(r"gprofiler(?:\..+)?")
LOGS_FORMAT = "[%(asctime)s] %(levelname)s: %(name)s: %(message)s"


def get_logger_adapter(logger_name: str) -> logging.LoggerAdapter:
Expand Down Expand Up @@ -137,10 +138,7 @@ def initial_root_logger_setup(

stream_handler = logging.StreamHandler(stream=sys.stdout)
stream_handler.setLevel(stream_level)
if stream_level < logging.INFO:
stream_handler.setFormatter(GProfilerFormatter("[%(asctime)s] %(levelname)s: %(name)s: %(message)s"))
else:
stream_handler.setFormatter(GProfilerFormatter("[%(asctime)s] %(message)s", "%H:%M:%S"))
stream_handler.setFormatter(GProfilerFormatter(LOGS_FORMAT))
logger_adapter.logger.addHandler(stream_handler)

os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
Expand All @@ -150,7 +148,7 @@ def initial_root_logger_setup(
backupCount=rotate_backup_count,
)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(GProfilerFormatter("[%(asctime)s] %(levelname)s: %(name)s: %(message)s"))
file_handler.setFormatter(GProfilerFormatter(LOGS_FORMAT))
logger_adapter.logger.addHandler(file_handler)

if remote_logs_handler is not None:
Expand Down

0 comments on commit c2c9b91

Please sign in to comment.