From cc23412d7a4841667179d70571689bb41a167d32 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 29 Jun 2012 14:42:06 -0700 Subject: If logging hasn't been enabled via '--debug' at least log the exceptions that occur to stderr. --- bin/cloud-init | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/cloud-init b/bin/cloud-init index 0330cb2b..22901e15 100755 --- a/bin/cloud-init +++ b/bin/cloud-init @@ -24,6 +24,7 @@ import argparse import os import sys +import traceback # This is more just for running from the bin folder so that # cloud-init binary can find the cloudinit module @@ -64,6 +65,18 @@ FREQ_SHORT_NAMES = { LOG = logging.getLogger() +# Used for when a logger may not be active +# and we still want to print exceptions... +def print_exc(msg=''): + if msg: + sys.stderr.write("%s\n" % (msg)) + sys.stderr.write('-' * 60) + sys.stderr.write("\n") + traceback.print_exc(file=sys.stderr) + sys.stderr.write('-' * 60) + sys.stderr.write("\n") + + def welcome(action): msg = ("Cloud-init v. {{version}} running '{{action}}' at " "{{timestamp}}. Up {{uptime}} seconds.") @@ -151,6 +164,7 @@ def main_init(name, args): (outfmt, errfmt) = util.fixup_output(init.cfg, name) except: util.logexc(LOG, "Failed to setup output redirection!") + print_exc("Failed to setup output redirection!") if args.debug: # Reset so that all the debug handlers are closed out LOG.debug(("Logging being reset, this logger may no" @@ -277,6 +291,9 @@ def main_modules(action_name, args): util.logexc(LOG, ('Can not apply stage %s, ' 'no datasource found!' " Likely bad things to come!"), name) + print_exc(('Can not apply stage %s, ' + 'no datasource found!' + " Likely bad things to come!") % (name)) if not args.force: return 1 # Stage 3 @@ -326,6 +343,8 @@ def main_single(name, args): # the module being ran (so continue on) util.logexc(LOG, ("Failed to fetch your datasource," " likely bad things to come!")) + print_exc(("Failed to fetch your datasource," + " likely bad things to come!")) if not args.force: return 1 # Stage 3 -- cgit v1.2.3