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 | 39991810f14b836e99d184f554d0354a96eaa0c7 (patch) | |
tree | ae8ba83c93e4a5602baafac752afdba6dd4260af | |
parent | d2dc2bb2585c97fc54847950a8c2f74a77ef9526 (diff) | |
download | definitions-39991810f14b836e99d184f554d0354a96eaa0c7.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.
-rw-r--r-- | writeexts.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/writeexts.py b/writeexts.py index c3605b1c..5102bfdc 100644 --- a/writeexts.py +++ b/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() |