summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-10-16 21:14:51 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-10-16 21:14:51 -0700
commit85a412c172044ae89d381f69ddb309ce8b3cea6e (patch)
tree843796507c470c9017afeeda2aa778041486ba00
parent7029732d496181233f2115dbfd65b13d20aceca7 (diff)
downloadvyos-cloud-init-85a412c172044ae89d381f69ddb309ce8b3cea6e.tar.gz
vyos-cloud-init-85a412c172044ae89d381f69ddb309ce8b3cea6e.zip
Move the recursive flushing to the log module.
-rw-r--r--cloudinit/config/cc_package_update_upgrade_install.py15
-rw-r--r--cloudinit/log.py12
2 files changed, 14 insertions, 13 deletions
diff --git a/cloudinit/config/cc_package_update_upgrade_install.py b/cloudinit/config/cc_package_update_upgrade_install.py
index e319e147..73b0e30d 100644
--- a/cloudinit/config/cc_package_update_upgrade_install.py
+++ b/cloudinit/config/cc_package_update_upgrade_install.py
@@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from logging import StreamHandler
import os
import time
+from cloudinit import log as logging
from cloudinit import util
REBOOT_FILE = "/var/run/reboot-required"
@@ -33,17 +33,6 @@ def _multi_cfg_bool_get(cfg, *keys):
return False
-def _flush_loggers(root):
- for h in root.handlers:
- if isinstance(h, (StreamHandler)):
- try:
- h.flush()
- except IOError:
- pass
- if root.parent:
- _flush_loggers(root.parent)
-
-
def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
util.subp(REBOOT_CMD)
start = time.time()
@@ -98,7 +87,7 @@ def handle(_name, cfg, cloud, log, _args):
try:
log.warn("Rebooting after upgrade or install per %s", REBOOT_FILE)
# Flush the above warning + anything else out...
- _flush_loggers(log)
+ logging.flushLoggers(log)
_fire_reboot(log)
except Exception as e:
util.logexc(log, "Requested reboot did not happen!")
diff --git a/cloudinit/log.py b/cloudinit/log.py
index 2333e5ee..da6c2851 100644
--- a/cloudinit/log.py
+++ b/cloudinit/log.py
@@ -53,6 +53,18 @@ def setupBasicLogging():
root.setLevel(DEBUG)
+def flushLoggers(root):
+ if not root:
+ return
+ for h in root.handlers:
+ if isinstance(h, (logging.StreamHandler)):
+ try:
+ h.flush()
+ except IOError:
+ pass
+ flushLoggers(root.parent)
+
+
def setupLogging(cfg=None):
# See if the config provides any logging conf...
if not cfg: