aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/utils
diff options
context:
space:
mode:
authorDiego Russo <diego.russo@arm.com>2023-02-02 22:04:05 +0000
committerDiego Russo <diego.russo@arm.com>2023-02-03 17:48:11 +0000
commitf1eaff3c9790464bed3183ff76555cf815166f50 (patch)
treebba288bb051925a692e1e1f998f7cc48df755df6 /src/mlia/utils
parentd1b2374cda6811a93d1174400fc2eecd7100a8c3 (diff)
downloadmlia-f1eaff3c9790464bed3183ff76555cf815166f50.tar.gz
MLIA-782 Remove --output parameter
* Remove --output parameter from argument parser * Remove FormattedFilePath class and its presence across the codebase * Move logging module from cli to core * The output format is now injected in the execution context and used across MLIA * Depending on the output format, TextReporter and JSONReporter have been created and used accordingly. * The whole output to standard output and/or logfile is driven via the logging module: the only case where the print is used is when the --json parameter is specified. This is needed becase all output (including third party application as well) needs to be disabled otherwise it might corrupt the json output in the standard output. * Debug information is logged into the log file and printed to stdout when the output format is plain_text. * Update E2E test and config to cope with the new mechanism of outputting json data to standard output. Change-Id: I4395800b0b1af4d24406a828d780bdeef98cd413
Diffstat (limited to 'src/mlia/utils')
-rw-r--r--src/mlia/utils/logging.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/mlia/utils/logging.py b/src/mlia/utils/logging.py
index 0659dcf..17f6cae 100644
--- a/src/mlia/utils/logging.py
+++ b/src/mlia/utils/logging.py
@@ -18,6 +18,8 @@ from typing import Generator
from typing import Iterable
from typing import TextIO
+from mlia.utils.console import remove_ascii_codes
+
class LoggerWriter:
"""Redirect printed messages to the logger."""
@@ -152,12 +154,21 @@ class LogFilter(logging.Filter):
return cls(skip_by_level)
+class NoASCIIFormatter(logging.Formatter):
+ """Custom Formatter for logging into file."""
+
+ def format(self, record: logging.LogRecord) -> str:
+ """Overwrite format method to remove ascii codes from record."""
+ result = super().format(record)
+ return remove_ascii_codes(result)
+
+
def create_log_handler(
*,
file_path: Path | None = None,
stream: Any | None = None,
log_level: int | None = None,
- log_format: str | None = None,
+ log_format: str | logging.Formatter | None = None,
log_filter: logging.Filter | None = None,
delay: bool = True,
) -> logging.Handler:
@@ -176,7 +187,9 @@ def create_log_handler(
handler.setLevel(log_level)
if log_format:
- handler.setFormatter(logging.Formatter(log_format))
+ if isinstance(log_format, str):
+ log_format = logging.Formatter(log_format)
+ handler.setFormatter(log_format)
if log_filter:
handler.addFilter(log_filter)