Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
markmcdowall committed Jul 30, 2018
2 parents d5f5a66 + 313d12b commit b703caf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dist: trusty

python:
- "2.7"
- "3.6"

env:
matrix:
Expand Down
6 changes: 3 additions & 3 deletions apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
limitations under the License.
"""

from pycompssapp import PyCOMPSsApp
from localapp import LocalApp
from workflowapp import WorkflowApp
from apps.pycompssapp import PyCOMPSsApp
from apps.localapp import LocalApp
from apps.workflowapp import WorkflowApp
5 changes: 3 additions & 2 deletions apps/jsonapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from apps.workflowapp import WorkflowApp
from basic_modules.metadata import Metadata
from utils import logger


class JSONApp(WorkflowApp): # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -77,7 +78,7 @@ def launch(self, tool_class, # pylint: disable=too-many-locals,arguments-differ
>>> # writes /path/to/results.json
"""

print "0) Unpack information from JSON"
logger.info("0) Unpack information from JSON")
input_ids, arguments, output_files = self._read_config(
config_path)

Expand Down Expand Up @@ -105,7 +106,7 @@ def launch(self, tool_class, # pylint: disable=too-many-locals,arguments-differ
tool_class, input_files, input_metadata,
output_files, arguments)

print "4) Pack information to JSON"
logger.info("4) Pack information to JSON")
return self._write_results(
input_files, input_metadata,
output_files, output_metadata,
Expand Down
7 changes: 4 additions & 3 deletions basic_modules/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import print_function
from basic_modules.metadata import Metadata # pylint: disable=unused-import
from utils import logger


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -98,10 +99,10 @@ def launch(self, tool_class, # pylint: disable=too-many-arguments
>>> app.launch(Tool, {"input": <input_file>}, {})
"""

print("1) Instantiate and configure Tool")
logger.info("1) Instantiate and configure Tool")
tool_instance = self._instantiate_tool(tool_class, configuration)

print("2) Run Tool")
logger.info("2) Run Tool")
input_files, input_metadata = self._pre_run(tool_instance,
input_files,
input_metadata)
Expand All @@ -114,7 +115,7 @@ def launch(self, tool_class, # pylint: disable=too-many-arguments
output_files,
output_metadata)

print("Output_files: ", output_files)
logger.info("Output_files: ", output_files)
return output_files, output_metadata

def _instantiate_tool(self, tool_class, configuration): # pylint: disable=no-self-use
Expand Down
19 changes: 10 additions & 9 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
limitations under the License.
"""

import re
import pytest

from utils import logger
Expand All @@ -27,7 +28,7 @@ def test_debug(capsys):
"""
logger.debug("test")
captured = capsys.readouterr()
assert captured[0] == "DEBUG: test\n"
assert re.search("DEBUG: test", captured[0])


@pytest.mark.info
Expand All @@ -37,7 +38,7 @@ def test_info(capsys):
"""
logger.info("test")
captured = capsys.readouterr()
assert captured[0] == "INFO: test\n"
assert re.search("INFO: test", captured[0])


@pytest.mark.warn
Expand All @@ -47,7 +48,7 @@ def test_warn(capsys):
"""
logger.warn("test")
captured = capsys.readouterr()
assert captured[1] == "WARNING: test\n"
assert re.search("WARNING: test", captured[1])


@pytest.mark.error
Expand All @@ -57,7 +58,7 @@ def test_error(capsys):
"""
logger.error("test")
captured = capsys.readouterr()
assert captured[1] == "ERROR: test\n"
assert re.search("ERROR: test", captured[1])


@pytest.mark.fatal
Expand All @@ -67,7 +68,7 @@ def test_fatal(capsys):
"""
logger.fatal("test")
captured = capsys.readouterr()
assert captured[1] == "FATAL: test\n"
assert re.search("FATAL: test", captured[1])


@pytest.mark.progress
Expand All @@ -77,7 +78,7 @@ def test_progress_00(capsys):
"""
logger.progress("test")
captured = capsys.readouterr()
assert captured[0] == "PROGRESS: test\n"
assert re.search("PROGRESS: test", captured[0])


@pytest.mark.progress
Expand All @@ -87,11 +88,11 @@ def test_progress_01(capsys):
"""
logger.progress("test", status="RUNNING")
captured = capsys.readouterr()
assert captured[0] == "PROGRESS: test - RUNNING\n"
assert re.search("PROGRESS: test - RUNNING", captured[0])

logger.progress("test", status="DONE")
captured = capsys.readouterr()
assert captured[0] == "PROGRESS: test - DONE\n"
assert re.search("PROGRESS: test - DONE", captured[0])


@pytest.mark.progress
Expand All @@ -101,4 +102,4 @@ def test_progress_02(capsys):
"""
logger.progress("test", task_id=2, total=5)
captured = capsys.readouterr()
assert captured[0] == "PROGRESS: test (2/5)\n"
assert re.search("PROGRESS: test \(2\/5\)", captured[0])
12 changes: 10 additions & 2 deletions utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import sys
import datetime

"""
This is the logging facility of the mg-tool-api. It is meant to provide
Expand Down Expand Up @@ -66,13 +67,20 @@


def __log(level, message, *args, **kwargs):
"""
Function to print out the logging input
"""
log_time = datetime.datetime.now()
log_ts = "{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(
log_time.year, log_time.month, log_time.day,
log_time.hour, log_time.minute, log_time.second)
if level not in _levelNames:
level = INFO
outstream = sys.stdout
if level in STDERR_LEVELS:
outstream = sys.stderr
outstream.write("{}: {}\n".format(
_levelNames[level], message.format(*args, **kwargs)))
outstream.write("{} | {}: {}\n".format(
log_ts, _levelNames[level], message.format(*args, **kwargs)))
return True


Expand Down

0 comments on commit b703caf

Please sign in to comment.