summaryrefslogtreecommitdiffstats
path: root/repo_logging.py
diff options
context:
space:
mode:
Diffstat (limited to 'repo_logging.py')
-rw-r--r--repo_logging.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/repo_logging.py b/repo_logging.py
index b748df4f..e94af7df 100644
--- a/repo_logging.py
+++ b/repo_logging.py
@@ -15,7 +15,7 @@
15"""Logic for printing user-friendly logs in repo.""" 15"""Logic for printing user-friendly logs in repo."""
16 16
17import logging 17import logging
18import multiprocessing 18from typing import Any, List
19 19
20from color import Coloring 20from color import Coloring
21 21
@@ -45,31 +45,25 @@ class ConfigMock:
45class RepoLogger(logging.Logger): 45class RepoLogger(logging.Logger):
46 """Repo Logging Module.""" 46 """Repo Logging Module."""
47 47
48 # Aggregates error-level logs. This is used to generate an error summary 48 def __init__(self, name: str, config=None, **kwargs):
49 # section at the end of a command execution.
50 errors = multiprocessing.Manager().list()
51
52 def __init__(self, name, config=None, **kwargs):
53 super().__init__(name, **kwargs) 49 super().__init__(name, **kwargs)
54 self.config = config if config else ConfigMock() 50 self.config = config if config else ConfigMock()
55 self.colorer = LogColoring(self.config) 51 self.colorer = LogColoring(self.config)
56 52
57 def error(self, msg, *args, **kwargs): 53 def error(self, msg: Any, *args, **kwargs):
58 """Print and aggregate error-level logs.""" 54 """Print and aggregate error-level logs."""
59 colored_error = self.colorer.error(msg, *args) 55 colored_error = self.colorer.error(str(msg), *args)
60 RepoLogger.errors.append(colored_error)
61
62 super().error(colored_error, **kwargs) 56 super().error(colored_error, **kwargs)
63 57
64 def warning(self, msg, *args, **kwargs): 58 def warning(self, msg: Any, *args, **kwargs):
65 """Print warning-level logs with coloring.""" 59 """Print warning-level logs with coloring."""
66 colored_warning = self.colorer.warning(msg, *args) 60 colored_warning = self.colorer.warning(str(msg), *args)
67 super().warning(colored_warning, **kwargs) 61 super().warning(colored_warning, **kwargs)
68 62
69 def log_aggregated_errors(self): 63 def log_aggregated_errors(self, errors: List[Exception]):
70 """Print all aggregated logs.""" 64 """Print all aggregated logs."""
71 super().error(self.colorer.error(SEPARATOR)) 65 super().error(self.colorer.error(SEPARATOR))
72 super().error( 66 super().error(
73 self.colorer.error("Repo command failed due to following errors:") 67 self.colorer.error("Repo command failed due to following errors:")
74 ) 68 )
75 super().error("\n".join(RepoLogger.errors)) 69 super().error("\n".join(map(str, errors)))