aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-05-01 14:13:00 -0700
committerBen Pfaff <blp@nicira.com>2012-05-22 10:17:05 -0700
commit8ba37945d690d0b7179b4aaf21a54fb300f574b0 (patch)
tree82d2e538c9f11f17b35964e870a38c646e980265 /python
parent53cf9963ccc60b443d738b31fbb446bc79170693 (diff)
python: Implement "vlog/reopen" unixctl command in Python vlog.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/vlog.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/python/ovs/vlog.py b/python/ovs/vlog.py
index b585591b..b3a8b813 100644
--- a/python/ovs/vlog.py
+++ b/python/ovs/vlog.py
@@ -1,5 +1,5 @@
-# Copyright (c) 2011 Nicira, Inc.
+# Copyright (c) 2011, 2012 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import socket
import sys
import ovs.dirs
+import ovs.unixctl
import ovs.util
FACILITIES = {"console": "info", "file": "info", "syslog": "info"}
@@ -41,6 +42,8 @@ class Vlog:
__inited = False
__msg_num = 0
__mfl = {} # Module -> facility -> level
+ __log_file = None
+ __file_handler = None
def __init__(self, name):
"""Creates a new Vlog object representing a module called 'name'. The
@@ -99,6 +102,7 @@ class Vlog:
Vlog.__inited = True
logging.raiseExceptions = False
+ Vlog.__log_file = log_file
for f in FACILITIES:
logger = logging.getLogger(f)
logger.setLevel(logging.DEBUG)
@@ -110,11 +114,15 @@ class Vlog:
logger.addHandler(logging.handlers.SysLogHandler(
address="/dev/log",
facility=logging.handlers.SysLogHandler.LOG_DAEMON))
- elif f == "file" and log_file:
- logger.addHandler(logging.FileHandler(log_file))
+ elif f == "file" and Vlog.__log_file:
+ Vlog.__file_handler = logging.FileHandler(Vlog.__log_file)
+ logger.addHandler(Vlog.__file_handler)
except (IOError, socket.error):
logger.setLevel(logging.CRITICAL)
+ ovs.unixctl.command_register("vlog/reopen", "", 0, 0,
+ Vlog._unixctl_vlog_reopen, None)
+
@staticmethod
def set_level(module, facility, level):
""" Sets the log level of the 'module'-'facility' tuple to 'level'.
@@ -149,6 +157,25 @@ class Vlog:
for f in facilities:
Vlog.__mfl[m][f] = level
+ @staticmethod
+ def reopen_log_file():
+ """Closes and then attempts to re-open the current log file. (This is
+ useful just after log rotation, to ensure that the new log file starts
+ being used.)"""
+
+ if Vlog.__log_file:
+ logger = logging.getLogger("file")
+ logger.removeHandler(Vlog.__file_handler)
+ Vlog.__file_handler = logging.FileHandler(Vlog.__log_file)
+ logger.addHandler(Vlog.__file_handler)
+
+ @staticmethod
+ def _unixctl_vlog_reopen(conn, unused_argv, unused_aux):
+ if Vlog.__log_file:
+ Vlog.reopen_log_file()
+ conn.reply(None)
+ else:
+ conn.reply("Logging to file not configured")
def add_args(parser):
"""Adds vlog related options to 'parser', an ArgumentParser object. The