diff --git a/IPython/config/configurable.py b/IPython/config/configurable.py index cd661d7..24970cc 100644 --- a/IPython/config/configurable.py +++ b/IPython/config/configurable.py @@ -1,31 +1,11 @@ # encoding: utf-8 -""" -A base class for objects that are configurable. +"""A base class for objects that are configurable.""" -Inheritance diagram: +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -.. inheritance-diagram:: IPython.config.configurable - :parts: 3 - -Authors: - -* Brian Granger -* Fernando Perez -* Min RK -""" from __future__ import print_function -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - import logging from copy import deepcopy @@ -375,16 +355,12 @@ class LoggingConfigurable(Configurable): """A parent class for Configurables that log. Subclasses have a log trait, and the default behavior - is to get the logger from the currently running Application - via Application.instance().log. + is to get the logger from the currently running Application. """ log = Instance('logging.Logger') def _log_default(self): - from IPython.config.application import Application - if Application.initialized(): - return Application.instance().log - else: - return logging.getLogger() + from IPython.utils import log + return log.get_logger() diff --git a/IPython/config/loader.py b/IPython/config/loader.py index a29e5d5..160739b 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -1,27 +1,8 @@ -"""A simple configuration system. +# encoding: utf-8 +"""A simple configuration system.""" -Inheritance diagram: - -.. inheritance-diagram:: IPython.config.loader - :parts: 3 - -Authors -------- -* Brian Granger -* Fernando Perez -* Min RK -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import argparse import copy @@ -308,11 +289,8 @@ class ConfigLoader(object): """ def _log_default(self): - from IPython.config.application import Application - if Application.initialized(): - return Application.instance().log - else: - return logging.getLogger() + from IPython.utils.log import get_logger + return get_logger() def __init__(self, log=None): """A base class for config loaders. diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index 56772f9..d8d107c 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -1,21 +1,7 @@ -"""Base Tornado handlers for the notebook. - -Authors: - -* Brian Granger -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +"""Base Tornado handlers for the notebook.""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import functools import json diff --git a/IPython/nbformat/current.py b/IPython/nbformat/current.py index 5688e50..b2ad9b2 100644 --- a/IPython/nbformat/current.py +++ b/IPython/nbformat/current.py @@ -1,21 +1,4 @@ -"""The official API for working with notebooks in the current format version. - -Authors: - -* Brian Granger -* Jonathan Frederic -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +"""The official API for working with notebooks in the current format version.""" from __future__ import print_function @@ -37,12 +20,8 @@ from .reader import versions from .convert import convert from .validator import validate -import logging -logger = logging.getLogger('NotebookApp') +from IPython.utils.log import get_logger -#----------------------------------------------------------------------------- -# Code -#----------------------------------------------------------------------------- current_nbformat = nbformat current_nbformat_minor = nbformat_minor @@ -88,7 +67,7 @@ def reads_json(nbjson, **kwargs): nb_current = convert(nb, current_nbformat) errors = validate(nb_current) if errors: - logger.error( + get_logger().error( "Notebook JSON is invalid (%d errors detected during read)", len(errors)) return nb_current @@ -101,7 +80,7 @@ def writes_json(nb, **kwargs): """ errors = validate(nb) if errors: - logger.error( + get_logger().error( "Notebook JSON is invalid (%d errors detected during write)", len(errors)) nbjson = versions[current_nbformat].writes_json(nb, **kwargs) diff --git a/IPython/parallel/controller/scheduler.py b/IPython/parallel/controller/scheduler.py index ecd73a5..1894b93 100644 --- a/IPython/parallel/controller/scheduler.py +++ b/IPython/parallel/controller/scheduler.py @@ -3,21 +3,10 @@ The Pure ZMQ scheduler does not allow routing schemes other than LRU, nor does it check msg_id DAG dependencies. For those, a slightly slower Python Scheduler exists. - -Authors: - -* Min RK """ -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- -#---------------------------------------------------------------------- -# Imports -#---------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import logging import sys diff --git a/IPython/parallel/util.py b/IPython/parallel/util.py index ee4084f..870063e 100644 --- a/IPython/parallel/util.py +++ b/IPython/parallel/util.py @@ -27,6 +27,7 @@ except: import zmq from zmq.log import handlers +from IPython.utils.log import get_logger from IPython.external.decorator import decorator from IPython.config.application import Application @@ -296,7 +297,7 @@ def select_random_ports(n): def signal_children(children): """Relay interupt/term signals to children, for more solid process cleanup.""" def terminate_children(sig, frame): - log = Application.instance().log + log = get_logger() log.critical("Got signal %i, terminating children..."%sig) for child in children: child.terminate() diff --git a/IPython/utils/log.py b/IPython/utils/log.py new file mode 100644 index 0000000..cfbcd28 --- /dev/null +++ b/IPython/utils/log.py @@ -0,0 +1,25 @@ +"""Grab the global logger instance.""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +import logging + +_logger = None + +def get_logger(): + """Grab the global logger instance. + + If a global IPython Application is instantiated, grab its logger. + Otherwise, grab the root logger. + """ + global _logger + + if _logger is None: + from IPython.config import Application + if Application.initialized(): + _logger = Application.instance().log + else: + logging.basicConfig() + _logger = logging.getLogger() + return _logger diff --git a/IPython/utils/pickleutil.py b/IPython/utils/pickleutil.py index 8f58088..bb885b1 100644 --- a/IPython/utils/pickleutil.py +++ b/IPython/utils/pickleutil.py @@ -20,6 +20,7 @@ from .importstring import import_item from .py3compat import string_types, iteritems from IPython.config import Application +from IPython.utils.log import get_logger if py3compat.PY3: buffer = memoryview @@ -276,25 +277,11 @@ def CannedBuffer(CannedBytes): # Functions #------------------------------------------------------------------------------- -def _logger(): - """get the logger for the current Application - - the root logger will be used if no Application is running - """ - if Application.initialized(): - logger = Application.instance().log - else: - logger = logging.getLogger() - if not logger.handlers: - logging.basicConfig() - - return logger - def _import_mapping(mapping, original=None): """import any string-keys in a type mapping """ - log = _logger() + log = get_logger() log.debug("Importing canning map") for key,value in list(mapping.items()): if isinstance(key, string_types):