import os.path
import sys
+
if os.path.exists('/opt/aws/bin'):
sys.path.insert(0, '/opt/aws/bin')
from cfn_helper import *
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 = []
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:
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)
try:
metadata.cfn_hup(mainconfig.hooks)
except Exception as e:
- logging.exception("Error processing metadata")
+ logger.exception("Error processing metadata")
exit(1)
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)
try:
metadata.cfn_init()
except Exception as e:
- logging.exception("Error processing metadata")
+ logger.exception("Error processing metadata")
exit(1)