Skip to content

Commit

Permalink
feat(config): add logging config
Browse files Browse the repository at this point in the history
Use logging config from caput.
  • Loading branch information
nritsche committed Sep 18, 2020
1 parent ca500a2 commit 1aa53ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion bondia/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .util.exception import DataError

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

FILE_TYPES = {
"delayspectrum": "delayspectrum_lsd_*.h5",
Expand Down
1 change: 0 additions & 1 deletion bondia/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


logger = logging.getLogger(__name__)
logger.setLevel("DEBUG")


class BondiaGui:
Expand Down
11 changes: 9 additions & 2 deletions bondia/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from caput.config import Property, Reader
from caput.config import Property, Reader, logging_config
import holoviews as hv
from jinja2 import Environment, PackageLoader
from jinja2.exceptions import TemplateNotFound
Expand All @@ -10,10 +10,10 @@
from .gui import BondiaGui

logger = logging.getLogger(__name__)
logger.setLevel("DEBUG")


class BondiaServer(Reader):
logging = logging_config(default={"root": "INFO"})
_config_data = Property({}, proptype=dict, key="data")
_template_name = Property("mwc", str, "html_template")
_width_drawer_widgets = Property(220, int)
Expand All @@ -37,6 +37,13 @@ def __init__(self):
raise ConfigError(f"Can't find template '{self._template_name}'.")

def _finalise_config(self):
# Apply logging config
logging.basicConfig(level=getattr(logging, self.logging.get("root", "WARNING")))
for module, level in self.logging.items():
if module != "root":
logging.getLogger(module).setLevel(getattr(logging, level))
logger.debug(f"Applied logging config: {self.logging}")

self.data = DataLoader.from_config(self._config_data)
if not self.data.index:
raise ConfigError("No data available.")
Expand Down
15 changes: 10 additions & 5 deletions scripts/bondia-server
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ logger = logging.getLogger("bondia-server")
default=True,
show_default=True,
)
def start(configfile, show, port, num_procs, websocket_origin, login):
@click.option(
"--print-config/--no-print-config",
help="Print the config on start.",
default=True,
show_default=True,
)
def start(configfile, show, port, num_procs, websocket_origin, login, print_config):

# TODO: use caput.config
logging.basicConfig(level=logging.DEBUG)
logger.setLevel("DEBUG")
logging.basicConfig(level=logging.INFO)

logger.info(f"Starting bondia-server {__version__} with config from {configfile}.")
with pathlib.Path(configfile).open() as file:
config = yaml.safe_load(file)
logger.debug(f"Loaded config: {config}")
if print_config:
logger.info(f"Loaded config: {config}")

if isinstance(websocket_origin, str):
websocket_origin = [websocket_origin]
Expand Down

0 comments on commit 1aa53ef

Please sign in to comment.