Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging improvements #1617

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
entry_points={
'console_scripts': [
"starfish=starfish:starfish",
"starfish=starfish.core.starfish:starfish",
]
},
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion starfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from .core.intensity_table.decoded_intensity_table import DecodedIntensityTable
from .core.intensity_table.intensity_table import IntensityTable
from .core.segmentation_mask import SegmentationMaskCollection
from .core.starfish import starfish
from .core.util.logging import Log
20 changes: 14 additions & 6 deletions starfish/core/util/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import platform
from functools import lru_cache
from json import JSONEncoder
from typing import List, Mapping

import pkg_resources

# these are import statements and not from xxx import yyy to break a circular dependency.
import starfish.core
from starfish.core.types import CORE_DEPENDENCIES, LOG
import starfish.core.types


class Log:
Expand Down Expand Up @@ -35,7 +36,14 @@ def update_log(self, class_instance) -> None:
self._log.append(entry)

def encode(self):
return LogEncoder().encode({LOG: self.data})
return LogEncoder().encode({starfish.core.types.LOG: self._log})

@classmethod
def decode(cls, encoded_log: str):
log = json.loads(encoded_log)
log_object = Log()
log_object._log = log
return log_object

@property
def data(self):
Expand All @@ -45,7 +53,7 @@ def data(self):
@lru_cache(maxsize=1)
def get_core_dependency_info() -> Mapping[str, str]:
dependency_info = dict()
for dependency in CORE_DEPENDENCIES:
for dependency in starfish.core.types.CORE_DEPENDENCIES:
version = get_dependency_version(dependency)
dependency_info[dependency] = version
return dependency_info
Expand All @@ -69,7 +77,7 @@ def get_os_info() -> Mapping[str, str]:
"Python Version": platform.python_version()}


class LogEncoder(JSONEncoder):
class LogEncoder(json.JSONEncoder):
"""
JSON encodes the List[Dict] pipeline provence log. For simple
objects use default JSON encoding. For more complex objects
Expand All @@ -79,4 +87,4 @@ def default(self, o):
try:
return super(LogEncoder, self).default(o)
except TypeError:
return JSONEncoder().encode(repr(o))
return json.JSONEncoder().encode(repr(o))