From afb5f8da541f97a9fc5c023cac7dc55b5b81dd06 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 17 Jun 2010 11:29:34 -0400 Subject: add initial logging support This logging infrastructure in cloudinit: - uses python logging - allows user supplied config of logging.config.fileConfig format to be supplied in /etc/cloud/cloud.cfg or in cloud_config by user data. - by default, tries to use syslog, if that is not available, writes directly to /var/log/cloud-init.log (syslog will not be available yet when cloud-init runs) - when using syslog, the doc/21-cloudinit.conf file provides a rsyslogd file to be placed in /etc/rsyslog.d/ that will file [CLOUDINIT] messages to /var/log/cloud-init.log --- cloud-init.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index 15a98957..924f3350 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -23,6 +23,7 @@ import sys import cloudinit import cloudinit.util as util import time +import logging def warn(str): sys.stderr.write(str) @@ -37,9 +38,14 @@ def main(): warn("unable to open /proc/uptime\n") uptime = "na" - sys.stderr.write("cloud-init running: %s. up %s seconds\n" % (now, uptime)) + msg = "cloud-init running: %s. up %s seconds\n" % (now, uptime) + sys.stderr.write(msg) sys.stderr.flush() + cloudinit.logging_set_from_cfg_file() + log = logging.getLogger() + log.info(msg) + # cache is not instance specific, so it has to be purged cloudinit.purge_cache() -- cgit v1.2.3