Skip to content
Snippets Groups Projects
Commit a844c7ee authored by Stefano Borini's avatar Stefano Borini
Browse files

Removed print statements. Using log file

parent 5d3abacb
No related branches found
No related tags found
1 merge request!108Introduced log file option
......@@ -12,6 +12,8 @@ from .factory_registry_plugin import FactoryRegistryPlugin
from .core_evaluation_driver import CoreEvaluationDriver
from .core_mco_driver import CoreMCODriver
log = logging.getLogger(__name__)
class BDSSApplication(Application):
"""Main application for the BDSS.
......@@ -47,7 +49,7 @@ class BDSSApplication(Application):
try:
mgr.map(functools.partial(_import_extensions, plugins))
except NoMatches:
logging.info("No extensions found")
log.info("No extensions found")
super(BDSSApplication, self).__init__(plugins=plugins)
......@@ -56,7 +58,7 @@ def _import_extensions(plugins, ext):
"""Service routine extracted for testing.
Imports the extension in the plugins argument.
"""
logging.info("Found extension {}".format(ext.obj))
log.info("Found extension {}".format(ext.obj))
plugins.append(ext.obj)
......@@ -65,7 +67,8 @@ def _load_failure_callback(plugins, manager, entry_point, exception):
Reports failure to load a module through stevedore, using the
on_load_failure_callback option.
"""
logging.error(
log.error(
"Unable to load plugin {}. Exception: {}. Message: {}".format(
entry_point, exception.__class__.__name__, exception)
)
log.exception(exception)
import logging
import click
from ..bdss_application import BDSSApplication
......@@ -10,12 +11,26 @@ push_exception_handler(reraise_exceptions=True)
@click.command()
@click.option("--evaluate", is_flag=True)
@click.option("--logfile",
type=click.Path(exists=False),
help="If specified, the log filename. "
" If unspecified, the log will be written to stdout.")
@click.argument('workflow_filepath', type=click.Path(exists=True))
def run(evaluate, workflow_filepath):
def run(evaluate, logfile, workflow_filepath):
application = BDSSApplication(
evaluate=evaluate,
workflow_filepath=workflow_filepath
)
logging_config = {}
if logfile is not None:
logging_config["filename"] = logfile
application.run()
logging.basicConfig(**logging_config)
log = logging.getLogger(__name__)
try:
application = BDSSApplication(
evaluate=evaluate,
workflow_filepath=workflow_filepath
)
application.run()
except Exception as e:
log.exception(e)
from __future__ import print_function
import sys
import logging
......@@ -14,6 +12,8 @@ from .io.workflow_reader import (
CORE_EVALUATION_DRIVER_ID = plugin_id("core", "CoreEvaluationDriver")
log = logging.getLogger(__name__)
class CoreEvaluationDriver(BaseCoreDriver):
"""Main plugin that handles the execution of the MCO
......@@ -26,12 +26,12 @@ class CoreEvaluationDriver(BaseCoreDriver):
try:
workflow = self.workflow
except (InvalidVersionException, InvalidFileException) as e:
print(str(e), file=sys.stderr)
log.exception(e)
sys.exit(1)
mco_model = workflow.mco
if mco_model is None:
print("No MCO defined. Nothing to do. Exiting.")
log.info("No MCO defined. Nothing to do. Exiting.")
sys.exit(0)
mco_factory = mco_model.factory
......@@ -105,7 +105,7 @@ def _compute_layer_results(environment_data_values,
in_slots)
# execute data source, passing only relevant data values.
logging.info("Evaluating for Data Source {}".format(
log.info("Evaluating for Data Source {}".format(
factory.name))
res = evaluator.run(model, passed_data_values)
......@@ -118,7 +118,7 @@ def _compute_layer_results(environment_data_values,
len(res), factory.name, len(out_slots)
)
logging.error(error_txt)
log.error(error_txt)
raise RuntimeError(error_txt)
if len(res) != len(model.output_slot_names):
......@@ -133,7 +133,7 @@ def _compute_layer_results(environment_data_values,
len(model.output_slot_names)
)
logging.error(error_txt)
log.error(error_txt)
raise RuntimeError(error_txt)
# At this point, the returned data values are unnamed.
......@@ -173,7 +173,7 @@ def _get_data_values_from_mco(model, communicator):
" file is corrupted.").format(
len(mco_data_values), len(model.parameters)
)
logging.error(error_txt)
log.error(error_txt)
raise RuntimeError(error_txt)
# The data values obtained by the communicator are unnamed.
......
from __future__ import print_function
import sys
import logging
......@@ -44,12 +42,12 @@ class CoreMCODriver(BaseCoreDriver):
try:
workflow = self.workflow
except (InvalidVersionException, InvalidFileException) as e:
print(str(e), file=sys.stderr)
log.exception(e)
sys.exit(1)
mco_model = workflow.mco
if mco_model is None:
print("No MCO defined. Nothing to do. Exiting.")
log.info("No MCO defined. Nothing to do. Exiting.")
sys.exit(0)
mco_factory = mco_model.factory
......
......@@ -53,7 +53,6 @@ class TestWorkflowWriter(unittest.TestCase):
fp = StringIO()
wf = self._create_mock_workflow()
wfwriter.write(wf, fp)
print(fp.getvalue())
fp.seek(0)
wfreader = WorkflowReader(self.mock_registry)
wf_result = wfreader.read(fp)
......
......@@ -7,6 +7,8 @@ from force_bdss.core.input_slot_map import InputSlotMap
from force_bdss.core.workflow import Workflow
from ..factory_registry_plugin import IFactoryRegistryPlugin
log = logging.getLogger(__name__)
SUPPORTED_FILE_VERSIONS = ["1"]
......@@ -69,12 +71,12 @@ class WorkflowReader(HasStrictTraits):
try:
version = json_data["version"]
except KeyError:
logging.error("File missing version information")
log.error("File missing version information")
raise InvalidFileException("Corrupted input file, no version"
" specified")
if version not in SUPPORTED_FILE_VERSIONS:
logging.error(
log.error(
"File contains version {} that is not in the "
"list of supported versions {}".format(
version, SUPPORTED_FILE_VERSIONS)
......@@ -92,7 +94,7 @@ class WorkflowReader(HasStrictTraits):
wf.notification_listeners[:] = \
self._extract_notification_listeners(wf_data)
except KeyError as e:
logging.exception("Could not read file {}".format(file))
log.exception("Could not read file {}".format(file))
raise InvalidFileException("Could not read file {}. "
"Unable to find key {}".format(file, e))
return wf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment