diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-08-29 23:18:47 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-09-01 10:26:53 +0000 |
commit | 354253df295bb2815a9d5e0744b3aa98eea6aad9 (patch) | |
tree | c57313e6eca50816db6c1649dd4c4ff22d0d5465 /morphlib | |
parent | 6fba43005c52930ce0175df18122264c2f193448 (diff) | |
download | morph-354253df295bb2815a9d5e0744b3aa98eea6aad9.tar.gz |
deploy: Make Python extensions log debug messages to MORPH_LOG_FD by default
Previously logging was disabled for Python deploy extensions.
We get a lot of useful information for free in the log file by
doing this: the environment will be written when the subprocess starts,
and if it crashes the full backtrace will be written there too. Subcommand
execution with cliapp.runcmd() will also be logged.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/writeexts.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index c3605b1c..5102bfdc 100644 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -89,7 +89,30 @@ class WriteExtension(cliapp.Application): write extensions. ''' - + + def setup_logging(self): + '''Direct all logging output to MORPH_LOG_FD, if set. + + This file descriptor is read by Morph and written into its own log + file. + + This overrides cliapp's usual configurable logging setup. + + ''' + log_write_fd = int(os.environ.get('MORPH_LOG_FD', 0)) + + if log_write_fd == 0: + return + + formatter = logging.Formatter('%(message)s') + + handler = logging.StreamHandler(os.fdopen(log_write_fd, 'w')) + handler.setFormatter(formatter) + + logger = logging.getLogger() + logger.addHandler(handler) + logger.setLevel(logging.DEBUG) + def process_args(self, args): raise NotImplementedError() |