Commit 661d4387 authored by Piergiorgio Pancino's avatar Piergiorgio Pancino

add shared logging initialization function

parent bae08967
......@@ -17,6 +17,17 @@ from bliss.common.mapping import _BEAMLINE_MAP, BEAMLINE_GRAPH, format_node
__all__ = ["log", "lslog", "lsdebug"]
def logging_startup(
log_level=logging.DEBUG, fmt="%(levelname)s %(asctime)-15s %(name)s: %(message)s"
):
"""
Provides basicConfig functionality to bliss activating at proper level the root loggers
"""
logging.basicConfig(level=log_level, format=fmt)
logging.getLogger("bliss").setLevel(log_level)
logging.getLogger("beamline").setLevel(log_level)
class LogMixin:
@autocomplete_property
def _logger(self, *args, **kwargs):
......
......@@ -35,11 +35,13 @@ import os
import sys
import subprocess
from docopt import docopt, DocoptExit
import logging
from bliss import release
from bliss.config import static
from bliss.config.static import Node
from bliss.config.conductor import client
from bliss.common.logtools import logging_startup
from .repl import embed
from . import session_files_templates as sft
......@@ -171,6 +173,10 @@ def main():
print("")
arguments = docopt(__doc__)
# initialize logging
log_level = getattr(logging, arguments["--log-level"][0].upper())
logging_startup(log_level)
# Print version
if arguments["--version"]:
print(("BLISS version %s" % release.short_version))
......
......@@ -8,19 +8,16 @@
import sys
from bliss.shell.cli.repl import embed
from bliss.common.logtools import logging_startup
import logging
fmt = "%(levelname)s %(asctime)-15s %(name)s: %(message)s"
def main():
session_name = sys.argv[1]
log_level = getattr(logging, sys.argv[2].upper())
# activate logging for module-level and session-level loggers
logging.basicConfig(format=fmt)
logging.getLogger("bliss").setLevel(log_level)
logging.getLogger("beamline").setLevel(log_level)
# initialize logging
log_level = getattr(logging, sys.argv[2].upper())
logging_startup(log_level)
embed(session_name=session_name, use_tmux=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment