Skip to content

Commit

Permalink
Remove old logging config, add CLI logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Aug 8, 2024
1 parent 371287e commit f1c6b87
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 54 deletions.
48 changes: 0 additions & 48 deletions core/lls_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,9 @@
__version__ = "0.2.6"

from strenum import StrEnum
from enum import Enum
from pyclesperanto_prototype._tier8._affine_transform_deskew_3d import DeskewDirection

# Initialize configuration options

#Choice of Deconvolution
class DeconvolutionChoice(StrEnum):
cuda_gpu = "cuda_gpu"
opencl_gpu = "opencl_gpu"
cpu = "cpu"

#CONFIGURE LOGGING using a dictionary (can also be done with yaml file)
import logging.config
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,

'formatters': {
'default_formatter': {
'format': '[%(levelname)s:%(asctime)s] %(message)s'
},
},

'handlers': {
'stream_handler': {
'class': 'logging.StreamHandler',
'formatter': 'default_formatter',
},
},

'loggers': {
'': {
'handlers': ['stream_handler'],
'level': 'INFO',
'propagate': True
}
}
}

#Configuring logging level with empty string "" under the key loggers means its for root
#This will override levels for all other python libraries as they haven't been imported yet
#Specifying levels in each modules will override the root level

# Specify during initialization:
logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger(__name__)
logger.debug("Logging is configured.")

#specify an enum for log levels
class Log_Levels(Enum):
DEBUG = 10
INFO = 20
WARNING = 30

14 changes: 9 additions & 5 deletions core/lls_core/cmds/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from lls_core.models.crop import CropParams
from lls_core import DeconvolutionChoice
from typer import Typer, Argument, Option, Context, Exit
import logging
from rich.logging import RichHandler

from lls_core.models.output import SaveFileType
from pydantic import ValidationError
Expand Down Expand Up @@ -171,12 +173,14 @@ def process(
json_config: Optional[Path] = Option(None, show_default=False, help="Path to a JSON file from which parameters will be read."),
yaml_config: Optional[Path] = Option(None, show_default=False, help="Path to a YAML file from which parameters will be read."),

show_schema: bool = Option(default=False, help="If provided, image processing will not be performed, and instead a JSON document outlining the JSON/YAML options will be printed to stdout. This can be used to assist with writing a config file for use with the --json-config and --yaml-config options.")
show_schema: bool = Option(default=False, help="If provided, image processing will not be performed, and instead a JSON document outlining the JSON/YAML options will be printed to stdout. This can be used to assist with writing a config file for use with the --json-config and --yaml-config options."),
quiet: bool = Option(default=False, help="Silence all output.")
) -> None:
from click.core import ParameterSource
from rich.console import Console

console = Console(stderr=True)
# The quiet flag informs the logging config
# RichHandler lets us do "pretty" logging
logging.basicConfig(level=logging.WARNING if quiet else logging.INFO, handlers=[RichHandler()])

if show_schema:
import json
Expand Down Expand Up @@ -221,11 +225,11 @@ def process(
)
)
except ValidationError as e:
console.print(rich_validation(e))
logging.error(rich_validation(e), extra={"markup": True})
raise Exit(code=1)

lattice.save()
console.print(f"Processing successful. Results can be found in {lattice.save_dir.resolve()}")
logging.info(f"Processing successful. Results can be found in [bold]{lattice.save_dir.resolve()}[/]", extra={"markup": True})


def main():
Expand Down
10 changes: 9 additions & 1 deletion core/lls_core/models/lattice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from xarray import DataArray

import logging

logger = logging.getLogger(__name__)

class LatticeData(OutputParams, DeskewParams):
Expand Down Expand Up @@ -66,6 +65,15 @@ def read_image(cls, values: dict):
# Use the Deskew version of this validator, to do the actual image loading
return super().read_image(values)

@root_validator(pre=False)
def log_params(cls, values: dict):
"""
Prints out the final parameter state
"""
from rich.pretty import pretty_repr
logger.info(pretty_repr(values), extra={"markup": True})
return values

@validator("workflow", pre=True)
def parse_workflow(cls, v: Any):
# Load the workflow from disk if it was provided as a path
Expand Down

0 comments on commit f1c6b87

Please sign in to comment.