Ejemplo n.º 1
0
    def __init__(self, providers):
        self.providers = providers

        # If there's an application singleton, pass its configurables to the provider.  If
        # no application, still give provider a chance to handle configuration loading.
        config = None
        if Application.initialized():
            config = Application.instance().config

        for provider in providers:
            provider.load_config(config=config)
Ejemplo n.º 2
0
def app_or_module_logger(module_name):
    """
    If a global Application is instantiated, grab its logger.
    Otherwise, get a logger for the module name.
    """
    from traitlets.config import Application
    if Application.initialized():
        return Application.instance().log
    else:
        _logger = logging.getLogger(module_name)
        # Add a NullHandler to silence warnings about not being
        # initialized, per best practice for libraries.
        _logger.addHandler(logging.NullHandler())
        return _logger
Ejemplo n.º 3
0
    def get_logger(cls) -> logging.Logger:
        if cls._LOGGER is None:
            app = Application.instance()
            cls._LOGGER = logging.getLogger("{!s}.jupyterlab_git".format(
                app.log.name))

        return cls._LOGGER
Ejemplo n.º 4
0
    def get_logger(cls) -> logging.Logger:
        if cls._LOGGER is None:
            app = Application.instance()
            cls._LOGGER = logging.getLogger("{!s}.mamba_gator".format(
                app.log.name))
            app.clear_instance()

        return cls._LOGGER
Ejemplo n.º 5
0
    def _default_log(self):
        if self.parent and self.parent is IPython.get_ipython():
            # log to stdout in an IPython session
            log = logging.getLogger(f"{__name__}.{self.cluster_id}")
            log.setLevel(self.log_level)

            handler = logging.StreamHandler(sys.stdout)
            log.handlers = [handler]
            return log
        elif self.parent and getattr(self.parent, 'log', None) is not None:
            return self.parent.log
        elif Application.initialized():
            return Application.instance().log
        else:
            # set up our own logger
            log = logging.getLogger(f"{__name__}.{self.cluster_id}")
            log.setLevel(self.log_level)
            return log
Ejemplo n.º 6
0
    def _get_app_config(self):
        """Pulls application configuration 'section' relative to current class."""

        app_config = {}
        parent_app = Application.instance()
        if parent_app:
            # Collect config relative to our class instance.
            app_config = parent_app.config.get(self.__class__.__name__,
                                               {}).copy()
        return app_config
Ejemplo n.º 7
0
def set_engine_logger():
    '''Updates EMA logging on the engines with an EngineLoggerAdapter
    This adapter injects EMA as a topic into all messages
    '''

    logger = Application.instance().log
    logger.setLevel(ema_logging.DEBUG)

    for handler in logger.handlers:
        if isinstance(handler, EnginePUBHandler):  # @UndefinedVariable
            handler.setLevel(ema_logging.DEBUG)

    adapter = EngingeLoggerAdapter(logger, SUBTOPIC)
    ema_logging._logger = adapter

    ema_logging.debug('updated logger')
Ejemplo n.º 8
0
def set_engine_logger():
    '''Updates EMA logging on the engines with an EngineLoggerAdapter
    This adapter injects EMA as a topic into all messages
    '''

    logger = Application.instance().log
    logger.setLevel(ema_logging.DEBUG)

    for handler in logger.handlers:
        if isinstance(handler, EnginePUBHandler):  # @UndefinedVariable
            handler.setLevel(ema_logging.DEBUG)

    adapter = EngingeLoggerAdapter(logger, SUBTOPIC)
    ema_logging._logger = adapter

    ema_logging.debug('updated logger')
Ejemplo n.º 9
0
 def log(self):
     """use the IPython log by default, falling back on tornado's logger"""
     if Application.initialized():
         return Application.instance().log
     else:
         return app_log
Ejemplo n.º 10
0
def log():
    if Application.initialized():
        return Application.instance().log
    else:
        return app_log
Ejemplo n.º 11
0
)
from biokbase.narrative.common.util import kbase_env
import urllib
import tornado.log
from traitlets.config import Application
from biokbase.auth import (
    get_user_info,
    init_session_env
)
from biokbase.narrative.common.url_config import URLS

HTTPError = web.HTTPError

app_log = tornado.log.app_log  # alias
if Application.initialized:
    app_log = Application.instance().log

g_log = get_logger("biokbase.narrative")
auth_cookie_name = "kbase_session"

def _init_session(request, cookies):
    client_ip = request.remote_ip
    http_headers = request.headers
    ua = http_headers.get('User-Agent', 'unknown')
    auth_cookie = cookies.get(auth_cookie_name)
    if auth_cookie is not None:
        token = urllib.unquote(auth_cookie.value)
    else:
        raise web.HTTPError(status_code=401,
                            log_message='No auth cookie, denying access',
                            reason='Authorization required for Narrative access')
Ejemplo n.º 12
0
def log():
    if Application.initialized():
        return Application.instance().log
    else:
        return app_log
Ejemplo n.º 13
0
 def log(self):
     """use the IPython log by default, falling back on tornado's logger"""
     if Application.initialized():
         return Application.instance().log
     else:
         return app_log