Skip to content

Commit 34877b9

Browse files
author
notactuallyfinn
committed
adjusted logging a bit
1 parent 73467f5 commit 34877b9

File tree

7 files changed

+66
-45
lines changed

7 files changed

+66
-45
lines changed

src/hermes/commands/cli.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ def main() -> None:
7676

7777
log.info("Run subcommand %s", args.command.command_name)
7878
args.command(args)
79-
except HermesPluginRunError as e:
80-
log.error("An error occurred during the execution of a plugin %s (Find details in './hermes.log')",
81-
args.command.command_name)
82-
log.debug("Original exception was: %s", e)
79+
except HermesPluginRunError:
80+
log.critical(
81+
"An error occurred during the execution of the %s command (Find details in './hermes.log')",
82+
args.command.command_name,
83+
exc_info=1
84+
)
8385
sys.exit(2)
84-
except Exception as e:
85-
log.error("An error occurred during execution of %s (Find details in './hermes.log')",
86-
args.command.command_name)
87-
log.debug("Original exception was: %s", e)
86+
except Exception:
87+
log.critical(
88+
"An error occurred during execution of the %s command (Find details in './hermes.log')",
89+
args.command.command_name,
90+
exc_info=1
91+
)
8892
sys.exit(1)
8993

94+
log.info("Finished run of %s command successfully.", args.command.command_name)
9095
sys.exit(0)

src/hermes/commands/curate/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def __call__(self, args: argparse.Namespace) -> None:
4747
try:
4848
metadata = SoftwareMetadata.load_from_cache(ctx, "result")
4949
except Exception as e:
50-
self.log.error("The data from the process step could not be loaded or is invalid for some reason.")
50+
self.log.critical(
51+
"## The data from the process step could not be loaded or is invalid for some reason.",
52+
exc_info=1
53+
)
5154
raise HermesValidationError("The results of the process step are invalid.") from e
5255
ctx.finalize_step("process")
5356

@@ -56,15 +59,15 @@ def __call__(self, args: argparse.Namespace) -> None:
5659
try:
5760
plugin_func = self.plugins[plugin_name]()
5861
except KeyError:
59-
self.log.error(f"Plugin {plugin_name} not found.")
62+
self.log.error(f"## Curate plugin {plugin_name} not found.")
6063
raise MisconfigurationError(f"Curate plugin {plugin_name} not found.")
6164

6265
self.log.info(f"## Run curation plugin {plugin_name}")
6366
# run plugin
6467
try:
6568
curated_metadata = plugin_func(self, metadata)
6669
except Exception as e:
67-
self.log.error(f"Unknown error while executing the {plugin_name} plugin.")
70+
self.log.critical(f"## Unknown error while executing the {plugin_name} plugin.", exc_info=1)
6871
raise HermesPluginRunError(f"Something went wrong while running the curate plugin {plugin_name}") from e
6972

7073
self.log.info("## Store curated data")

src/hermes/commands/deposit/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ def __call__(self, args: argparse.Namespace) -> None:
144144
try:
145145
plugin_func = self.plugins[plugin_name]()
146146
except KeyError:
147-
self.log.error(f"Plugin {plugin_name} not found.")
147+
self.log.critical(f"## Deposit plugin {plugin_name} not found.")
148148
raise MisconfigurationError(f"Deposit plugin {self.settings.plugin} not found.")
149149

150150
self.log.info(f"## Run deposit plugin {plugin_name}")
151151
# run plugin
152152
try:
153153
plugin_func(self)
154154
except HermesValidationError as e:
155-
self.log.error(f"Error while executing {plugin_name}: {e}")
155+
self.log.critical(f"## Error while executing {plugin_name} plugin.", exc_info=1)
156156
raise HermesPluginRunError(
157157
f"Something went wrong while running the deposit plugin {self.settings.plugin}"
158158
) from e

src/hermes/commands/harvest/base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pydantic import BaseModel
1010

1111
from hermes.commands.base import HermesCommand, HermesPlugin
12+
from hermes.error import HermesPluginRunError, MisconfigurationError
1213
from hermes.model.context_manager import HermesContext
1314
from hermes.model import SoftwareMetadata
1415

@@ -40,8 +41,8 @@ def __call__(self, args: argparse.Namespace) -> None:
4041
self.args = args
4142

4243
if len(self.settings.sources) == 0:
43-
self.log.info("# No plugin was configured to be run and loaded.")
44-
return
44+
self.log.critical("# No harvest plugin was configured to be run and loaded.")
45+
raise MisconfigurationError("No harvest plugin was configured to be run and loaded.")
4546

4647
# Initialize the harvest cache directory here to indicate the step ran
4748
ctx = HermesContext()
@@ -55,15 +56,15 @@ def __call__(self, args: argparse.Namespace) -> None:
5556
try:
5657
plugin_func = self.plugins[plugin_name]()
5758
except KeyError:
58-
self.log.warning(f"Plugin {plugin_name} not found, skipping it now.")
59+
self.log.error(f"### Plugin {plugin_name} not found, skipping it now.")
5960
continue
6061

6162
self.log.info(f"### Run {plugin_name} plugin")
6263
# run plugin
6364
try:
6465
harvested_data = plugin_func(self)
6566
except Exception:
66-
self.log.warning(f"Unknown error while executing the {plugin_name} plugin, skipping it now.")
67+
self.log.exception(f"### Unknown error while executing the {plugin_name} plugin, skipping it now.")
6768
continue
6869

6970
self.log.info(f"### Store metadata harvested by {plugin_name} plugin")
@@ -73,5 +74,5 @@ def __call__(self, args: argparse.Namespace) -> None:
7374

7475
ctx.finalize_step('harvest')
7576
if not harvested_any:
76-
self.log.error("No harvest plugin ran successfully.")
77-
raise RuntimeError("No harvest plugin ran successfully.")
77+
self.log.critical("No harvest plugin ran successfully.")
78+
raise HermesPluginRunError("No harvest plugin ran successfully.")

src/hermes/commands/postprocess/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydantic import BaseModel
1111

1212
from hermes.commands.base import HermesCommand, HermesPlugin
13+
from hermes.error import HermesPluginRunError
1314

1415

1516
class HermesPostprocessPlugin(HermesPlugin):
@@ -36,6 +37,10 @@ def __call__(self, args: argparse.Namespace) -> None:
3637
self.args = args
3738
plugin_names = self.settings.run
3839

40+
if not plugin_names:
41+
self.log.warning("# No plugin was configured to be run yet the postprocess command was executed.")
42+
return
43+
3944
self.log.info("## Load and run the plugins")
4045
ran_any = False
4146
for plugin_name in plugin_names:
@@ -44,19 +49,19 @@ def __call__(self, args: argparse.Namespace) -> None:
4449
try:
4550
plugin_func = self.plugins[plugin_name]()
4651
except KeyError:
47-
self.log.error(f"Plugin {plugin_name} not found.")
52+
self.log.error(f"### Plugin {plugin_name} not found.")
4853
continue
4954

5055
self.log.info(f"### Run {plugin_name} plugin")
5156
# run plugin
5257
try:
5358
plugin_func(self)
5459
except Exception:
55-
self.log.error(f"Unknown error while executing the {plugin_name} plugin.")
60+
self.log.exception(f"### Unknown error while executing the {plugin_name} plugin.")
5661
continue
5762

5863
ran_any = True
5964

6065
if not ran_any:
61-
self.log.error("No postprocess plugin ran successfully.")
62-
raise RuntimeError("No postprocess plugin ran successfully.")
66+
self.log.critical("## No postprocess plugin ran successfully.")
67+
raise HermesPluginRunError("No postprocess plugin ran successfully.")

src/hermes/commands/process/base.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pydantic import BaseModel
1111

1212
from hermes.commands.base import HermesCommand, HermesPlugin
13-
from hermes.error import HermesPluginRunError
13+
from hermes.error import HermesPluginRunError, MisconfigurationError
1414
from hermes.model.api import SoftwareMetadata
1515
from hermes.model.context_manager import HermesContext
1616
from hermes.model.merge.action import MergeAction
@@ -39,9 +39,21 @@ class HermesProcessCommand(HermesCommand):
3939

4040
def __call__(self, args: argparse.Namespace) -> None:
4141
self.log.info("# Metadata processing")
42-
self.args = args
4342
merged_doc = ld_merge_dict([{}])
4443

44+
if not self.settings.plugins:
45+
self.log.critical(
46+
"# It was explicitly configured that no process plugin should be used."
47+
" Hint: Do not configure anything to use standard 'codemeta' plugin."
48+
)
49+
raise MisconfigurationError("Explicit configuration to use no process plugin.")
50+
51+
# Get all harvesters
52+
harvester_names = self.settings.sources if self.settings.sources else self.root_settings.harvest.sources
53+
if not harvester_names:
54+
self.log.critical("# No harvesters to merge from were configured.")
55+
raise MisconfigurationError("No harvesters to merge from were configured.")
56+
4557
self.log.info("## Load and run the plugins")
4658
any_strategies_loaded = False
4759
# add the strategies from the plugins
@@ -51,15 +63,15 @@ def __call__(self, args: argparse.Namespace) -> None:
5163
try:
5264
plugin_func = self.plugins[plugin_name]()
5365
except KeyError:
54-
self.log.warning(f"Plugin {plugin_name} not found, skipping it now.")
66+
self.log.error(f"### Plugin {plugin_name} not found, skipping it now.")
5567
continue
5668

5769
self.log.info(f"### Run {plugin_name} plugin")
5870
# run plugin
5971
try:
6072
additional_strategies = plugin_func(self)
6173
except Exception:
62-
self.log.warning(f"Unknown error while executing the {plugin_name} plugin, skipping it now.")
74+
self.log.exception(f"### Unknown error while executing the {plugin_name} plugin, skipping it now.")
6375
continue
6476

6577
self.log.info(f"### Add the strategies to the merge document {plugin_name} plugin")
@@ -68,44 +80,39 @@ def __call__(self, args: argparse.Namespace) -> None:
6880
any_strategies_loaded = True
6981

7082
if not any_strategies_loaded:
71-
self.log.error("No process plugin was ran successfully.")
72-
raise RuntimeError("No process plugin was ran successfully.")
83+
self.log.critical("## No process plugin was ran successfully.")
84+
raise HermesPluginRunError("No process plugin was ran successfully.")
7385

7486
ctx = HermesContext()
7587
ctx.prepare_step('harvest')
7688

89+
# merge data from harvesters
7790
self.log.info("## Merge the metadata of the harvesters")
78-
# Get all harvesters
79-
harvester_names = self.settings.sources if self.settings.sources else self.root_settings.harvest.sources
8091
merged_any = False
8192
for harvester in harvester_names:
82-
self.log.info(f"## Load data from {harvester} plugin")
93+
self.log.info(f"### Load data from {harvester} plugin")
8394
# load data from harvester
8495
try:
8596
metadata = SoftwareMetadata.load_from_cache(ctx, harvester)
8697
except Exception:
8798
# skip this harvester when the data is invalid
88-
self.log.warning(f"The data from the harvester {harvester} could not be loaded or is invalid.")
89-
self.log.info(f"## Aborting merge for {harvester}")
99+
self.log.exception(
100+
f"### The data from the harvester {harvester} could not be loaded or is invalid, skipping it now."
101+
)
90102
continue
91103

92-
self.log.info(f"## Merge data from {harvester} plugin")
104+
self.log.info(f"### Merge data from {harvester} plugin")
93105
# merge data into the merge dict
94106
try:
95107
merged_doc.update(metadata)
96108
except Exception as e:
97-
self.log.error(f"Merging the data from {harvester} plugin resulted in an error.")
98-
raise HermesPluginRunError(f"Merging the data from {harvester} plugin failed.") from e
109+
self.log.critical(f"### Merging the data from {harvester} plugin resulted in an error.", exc_info=True)
110+
raise RuntimeError(f"Merging the data from {harvester} plugin failed.") from e
99111
merged_any = True
100112

101113
# error if nothing was merged
102-
if harvester_names and not merged_any:
103-
self.log.error(
104-
f"""No metadata has been merged. {
105-
"No harvesters to merge from were supplied" if not harvester_names else
106-
"The merging failed for all harvesters."
107-
}"""
108-
)
114+
if not merged_any:
115+
self.log.critical("No metadata has been merged, the loading of the data failed for all harvesters.")
109116
raise RuntimeError("No metadata has been merged.")
110117

111118
self.log.info("## Store processed metadata")

src/hermes/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def init_logging():
6969
_loggers[log_name] = logging.getLogger(log_name)
7070

7171

72-
def getLogger(log_name):
72+
def getLogger(log_name) -> logging.Logger:
7373
init_logging()
7474
if log_name not in _loggers:
7575
_loggers[log_name] = logging.getLogger(log_name)

0 commit comments

Comments
 (0)