]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Re-add the file logging to cfn tools.
authorAngus Salkeld <asalkeld@redhat.com>
Thu, 26 Apr 2012 11:45:01 +0000 (21:45 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Thu, 26 Apr 2012 11:45:01 +0000 (21:45 +1000)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
heat/cfntools/cfn-hup
heat/cfntools/cfn-init

index 2d0c1cbfd29508e7e0af4d29fc15267359ba9431..44f6222692f832f28c0b7716b4dae1a12b513f74 100755 (executable)
@@ -22,6 +22,7 @@ import os
 import os.path
 import sys
 
+
 if os.path.exists('/opt/aws/bin'):
     sys.path.insert(0, '/opt/aws/bin')
     from cfn_helper import *
@@ -46,18 +47,23 @@ parser.add_argument('-v', '--verbose',
 args = parser.parse_args()
 # FIXME: implement real arg
 
+logger = logging.getLogger('cfn-hup')
+log_file_name = "/var/log/cfn-hup.log"
 log_format = '%(levelname)s [%(asctime)s] %(message)s'
-# setup stdout logging
+file_handler = logging.FileHandler(log_file_name)
+file_handler.setFormatter(logging.Formatter(log_format))
+logging.getLogger().addHandler(file_handler)
+
 if args.verbose:
-    logging.basicConfig(format=log_format, level=logging.DEBUG)
+    logger.basicConfig(format=log_format, level=logging.DEBUG)
 else:
-    logging.basicConfig(format=log_format, level=logging.INFO)
+    logger.basicConfig(format=log_format, level=logging.INFO)
 
 main_conf_path = '/etc/cfn/cfn-hup.conf'
 try:
     main_config_file = open(main_conf_path)
 except IOError as exc:
-    logging.error('Could not open main configuration at %s' % main_conf_path)
+    logger.error('Could not open main configuration at %s' % main_conf_path)
     exit(1)
 
 config_files = []
@@ -66,7 +72,7 @@ if os.path.exists(hooks_conf_path):
     try:
         config_files.append(open(hooks_conf_path))
     except IOError as exc:
-        logging.exception(exc)
+        logger.exception(exc)
 
 if args.config_dir and os.path.exists(args.config_dir):
     try:
@@ -74,21 +80,21 @@ if args.config_dir and os.path.exists(args.config_dir):
             config_files.append(open(os.path.join(args.config_dir, f)))
 
     except OSError as exc:
-        logging.exception(exc)
+        logger.exception(exc)
 
 if not config_files:
-    logging.error('No hook files found at %s or %s' % (hooks_conf_path,
+    logger.error('No hook files found at %s or %s' % (hooks_conf_path,
                                                        args.config_dir))
     exit(1)
 
 try:
     mainconfig = HupConfig([main_config_file] + config_files)
 except Exception as ex:
-    logging.error('Cannot load configuration: %s' % str(ex))
+    logger.error('Cannot load configuration: %s' % str(ex))
     exit(1)
 
 if not mainconfig.unique_resources_get():
-    logging.error('No hooks were found. Add some to %s or %s' % (hooks_conf_path,
+    logger.error('No hooks were found. Add some to %s or %s' % (hooks_conf_path,
                                                                  args.config_dir))
     exit(1)
 
@@ -102,5 +108,5 @@ for r in mainconfig.unique_resources_get():
     try:
         metadata.cfn_hup(mainconfig.hooks)
     except Exception as e:
-        logging.exception("Error processing metadata")
+        logger.exception("Error processing metadata")
         exit(1)
index 155289e4f8af319dae87ab8fdcb8724f3253be52..37e7a9118f07c0cda8f78445046d64beac8f884b 100755 (executable)
@@ -42,8 +42,13 @@ if os.path.exists('/opt/aws/bin'):
 else:
     from heat.cfntools.cfn_helper import *
 
+logger = logging.getLogger('cfn-init')
+log_file_name = "/var/log/cfn-init.log"
 log_format = '%(levelname)s [%(asctime)s] %(message)s'
-logging.basicConfig(format=log_format, level=logging.INFO)
+file_handler = logging.FileHandler(log_file_name)
+file_handler.setFormatter(logging.Formatter(log_format))
+logger.getLogger().addHandler(file_handler)
+logger.basicConfig(format=log_format, level=logging.DEBUG)
 
 description = " "
 parser = argparse.ArgumentParser(description=description)
@@ -79,5 +84,5 @@ metadata.retrieve()
 try:
     metadata.cfn_init()
 except Exception as e:
-    logging.exception("Error processing metadata")
+    logger.exception("Error processing metadata")
     exit(1)