iploggerapp.py
103 lines
| 3.0 KiB
| text/x-python
|
PythonLexer
MinRK
|
r3604 | #!/usr/bin/env python | ||
# encoding: utf-8 | ||||
""" | ||||
A simple IPython logger application | ||||
MinRK
|
r4018 | |||
Authors: | ||||
* MinRK | ||||
MinRK
|
r3604 | """ | ||
#----------------------------------------------------------------------------- | ||||
# 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 | ||||
#----------------------------------------------------------------------------- | ||||
import os | ||||
import sys | ||||
import zmq | ||||
MinRK
|
r4024 | from IPython.core.profiledir import ProfileDir | ||
MinRK
|
r3991 | from IPython.utils.traitlets import Bool, Dict, Unicode | ||
MinRK
|
r3989 | |||
MinRK
|
r3993 | from IPython.parallel.apps.baseapp import ( | ||
MinRK
|
r3992 | BaseParallelApplication, | ||
MinRK
|
r5172 | base_aliases, | ||
MinRK
|
r5214 | catch_config_error, | ||
MinRK
|
r3604 | ) | ||
MinRK
|
r3688 | from IPython.parallel.apps.logwatcher import LogWatcher | ||
MinRK
|
r3604 | |||
#----------------------------------------------------------------------------- | ||||
# Module level variables | ||||
#----------------------------------------------------------------------------- | ||||
#: The default config file name for this application | ||||
default_config_file_name = u'iplogger_config.py' | ||||
MinRK
|
r3990 | _description = """Start an IPython logger for parallel computing. | ||
MinRK
|
r3604 | |||
IPython controllers and engines (and your own processes) can broadcast log messages | ||||
by registering a `zmq.log.handlers.PUBHandler` with the `logging` module. The | ||||
logger can be configured using command line options or using a cluster | ||||
directory. Cluster directories contain config, log and security files and are | ||||
MinRK
|
r4024 | usually located in your ipython directory and named as "profile_name". | ||
Brian E. Granger
|
r4218 | See the `profile` and `profile-dir` options for details. | ||
MinRK
|
r3604 | """ | ||
#----------------------------------------------------------------------------- | ||||
# Main application | ||||
#----------------------------------------------------------------------------- | ||||
MinRK
|
r3989 | aliases = {} | ||
aliases.update(base_aliases) | ||||
aliases.update(dict(url='LogWatcher.url', topics='LogWatcher.topics')) | ||||
MinRK
|
r3604 | |||
MinRK
|
r3992 | class IPLoggerApp(BaseParallelApplication): | ||
MinRK
|
r3604 | |||
MinRK
|
r4025 | name = u'iplogger' | ||
MinRK
|
r3604 | description = _description | ||
MinRK
|
r3991 | config_file_name = Unicode(default_config_file_name) | ||
MinRK
|
r3989 | |||
MinRK
|
r3992 | classes = [LogWatcher, ProfileDir] | ||
MinRK
|
r3989 | aliases = Dict(aliases) | ||
MinRK
|
r5214 | @catch_config_error | ||
MinRK
|
r3989 | def initialize(self, argv=None): | ||
super(IPLoggerApp, self).initialize(argv) | ||||
self.init_watcher() | ||||
def init_watcher(self): | ||||
MinRK
|
r3604 | try: | ||
MinRK
|
r11064 | self.watcher = LogWatcher(parent=self, log=self.log) | ||
MinRK
|
r3604 | except: | ||
self.log.error("Couldn't start the LogWatcher", exc_info=True) | ||||
self.exit(1) | ||||
MinRK
|
r3989 | self.log.info("Listening for log messages on %r"%self.watcher.url) | ||
MinRK
|
r3604 | |||
MinRK
|
r3989 | def start(self): | ||
self.watcher.start() | ||||
MinRK
|
r3604 | try: | ||
self.watcher.loop.start() | ||||
except KeyboardInterrupt: | ||||
self.log.critical("Logging Interrupted, shutting down...\n") | ||||
def launch_new_instance(): | ||||
"""Create and run the IPython LogWatcher""" | ||||
MinRK
|
r3999 | app = IPLoggerApp.instance() | ||
MinRK
|
r3989 | app.initialize() | ||
MinRK
|
r3604 | app.start() | ||
if __name__ == '__main__': | ||||
launch_new_instance() | ||||