diff --git a/IPython/config/configurable.py b/IPython/config/configurable.py index fc69db8..5d3abe7 100755 --- a/IPython/config/configurable.py +++ b/IPython/config/configurable.py @@ -261,3 +261,18 @@ class SingletonConfigurable(Configurable): """Has an instance been created?""" return hasattr(cls, "_instance") and cls._instance is not None + +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. + """ + + log = Instance('logging.Logger') + def _log_default(self): + from IPython.config.application import Application + return Application.instance().log + + \ No newline at end of file diff --git a/IPython/parallel/apps/launcher.py b/IPython/parallel/apps/launcher.py index 2ba117f..521b6e9 100644 --- a/IPython/parallel/apps/launcher.py +++ b/IPython/parallel/apps/launcher.py @@ -50,7 +50,7 @@ except ImportError: from zmq.eventloop import ioloop from IPython.config.application import Application -from IPython.config.configurable import Configurable +from IPython.config.configurable import LoggingConfigurable from IPython.utils.text import EvalFormatter from IPython.utils.traitlets import Any, Int, List, Unicode, Dict, Instance from IPython.utils.path import get_ipython_module_path @@ -96,7 +96,7 @@ class UnknownStatus(LauncherError): pass -class BaseLauncher(Configurable): +class BaseLauncher(LoggingConfigurable): """An asbtraction for starting, stopping and signaling a process.""" # In all of the launchers, the work_dir is where child processes will be @@ -108,9 +108,6 @@ class BaseLauncher(Configurable): # the work_dir option. work_dir = Unicode(u'.') loop = Instance('zmq.eventloop.ioloop.IOLoop') - log = Instance('logging.Logger') - def _log_default(self): - return Application.instance().log start_data = Any() stop_data = Any() diff --git a/IPython/parallel/apps/logwatcher.py b/IPython/parallel/apps/logwatcher.py index 7686f33..17de05b 100644 --- a/IPython/parallel/apps/logwatcher.py +++ b/IPython/parallel/apps/logwatcher.py @@ -19,8 +19,7 @@ import sys import zmq from zmq.eventloop import ioloop, zmqstream -from IPython.config.application import Application -from IPython.config.configurable import Configurable +from IPython.config.configurable import LoggingConfigurable from IPython.utils.traitlets import Int, Unicode, Instance, List #----------------------------------------------------------------------------- @@ -28,17 +27,13 @@ from IPython.utils.traitlets import Int, Unicode, Instance, List #----------------------------------------------------------------------------- -class LogWatcher(Configurable): +class LogWatcher(LoggingConfigurable): """A simple class that receives messages on a SUB socket, as published by subclasses of `zmq.log.handlers.PUBHandler`, and logs them itself. This can subscribe to multiple topics, but defaults to all topics. """ - log = Instance('logging.Logger') - def _log_default(self): - return Application.instance().log - # configurables topics = List([''], config=True, help="The ZMQ topics to subscribe to. Default is to subscribe to all messages") diff --git a/IPython/parallel/controller/dictdb.py b/IPython/parallel/controller/dictdb.py index a7bb863..2d23a30 100644 --- a/IPython/parallel/controller/dictdb.py +++ b/IPython/parallel/controller/dictdb.py @@ -44,8 +44,7 @@ We support a subset of mongodb operators: from datetime import datetime -from IPython.config.application import Application -from IPython.config.configurable import Configurable +from IPython.config.configurable import LoggingConfigurable from IPython.utils.traitlets import Dict, Unicode, Instance @@ -80,13 +79,10 @@ class CompositeFilter(object): return False return True -class BaseDB(Configurable): +class BaseDB(LoggingConfigurable): """Empty Parent class so traitlets work on DB.""" # base configurable traits: session = Unicode("") - log = Instance('logging.Logger') - def _log_default(self): - return Application.instance().log class DictDB(BaseDB): """Basic in-memory dict-based object for saving Task Records. diff --git a/IPython/parallel/controller/heartmonitor.py b/IPython/parallel/controller/heartmonitor.py index f679421..c83c688 100644 --- a/IPython/parallel/controller/heartmonitor.py +++ b/IPython/parallel/controller/heartmonitor.py @@ -18,8 +18,7 @@ import zmq from zmq.devices import ThreadDevice from zmq.eventloop import ioloop, zmqstream -from IPython.config.application import Application -from IPython.config.configurable import Configurable +from IPython.config.configurable import LoggingConfigurable from IPython.utils.traitlets import Set, Instance, CFloat class Heart(object): @@ -48,7 +47,7 @@ class Heart(object): def start(self): return self.device.start() -class HeartMonitor(Configurable): +class HeartMonitor(LoggingConfigurable): """A basic HeartMonitor class pingstream: a PUB stream pongstream: an XREP stream @@ -59,10 +58,6 @@ class HeartMonitor(Configurable): ' (in ms) [default: 100]', ) - log = Instance('logging.Logger') - def _log_default(self): - return Application.instance().log - pingstream=Instance('zmq.eventloop.zmqstream.ZMQStream') pongstream=Instance('zmq.eventloop.zmqstream.ZMQStream') loop = Instance('zmq.eventloop.ioloop.IOLoop')