Change in vdsm[ovirt-3.5]: vdsm-tool: Add logging configuration.
dkuznets at redhat.com
dkuznets at redhat.com
Mon Jun 30 14:41:33 UTC 2014
Dima Kuznetsov has uploaded a new change for review.
Change subject: vdsm-tool: Add logging configuration.
......................................................................
vdsm-tool: Add logging configuration.
Added the following flags:
-l/--logfile
-v/vv/vvv/--v/vv/vvverbose
-a/--append
These flags allow specifying where to put the log, how verbose should it
be, and should it truncate the log file before writing.
Change-Id: Ia495743f6e869f65843404e4d4c25c146ff14b43
Signed-off-by: Dima Kuznetsov <dkuznets at redhat.com>
---
M init/vdsmd_init_common.sh.in
M vdsm-tool/vdsm-tool
2 files changed, 63 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/21/29421/1
diff --git a/init/vdsmd_init_common.sh.in b/init/vdsmd_init_common.sh.in
index 23eef83..e142470 100644
--- a/init/vdsmd_init_common.sh.in
+++ b/init/vdsmd_init_common.sh.in
@@ -19,6 +19,7 @@
#
VDSM_TOOL="@BINDIR@/vdsm-tool"
+UPGRADE_LOGGING_PARAMS="--vvverbose --append --logfile=@VDSMLOGDIR@/upgrade.log"
prog=vdsm
#### pre-start tasks ####
@@ -198,11 +199,11 @@
}
task_unified_network_persistence_upgrade(){
- "$VDSM_TOOL" upgrade-unified-persistence
+ "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-unified-persistence
}
task_upgrade_300_nets(){
- "$VDSM_TOOL" upgrade-3.0.0-networks
+ "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-3.0.0-networks
}
#### pre-start tasks end ####
diff --git a/vdsm-tool/vdsm-tool b/vdsm-tool/vdsm-tool
index 28a05af..8fa3bc5 100755
--- a/vdsm-tool/vdsm-tool
+++ b/vdsm-tool/vdsm-tool
@@ -23,6 +23,7 @@
import sys
import imp
import getopt
+import logging
import textwrap
import syslog
import traceback
@@ -122,10 +123,21 @@
def usage_and_exit(exit_code):
- print("Usage: %s [options] <action> [arguments]\n" % sys.argv[0])
-
- print("Valid options:", "\n",
- " -h, --help")
+ print('\n'.join(["Usage: %s [options] <action> [arguments]" % sys.argv[0],
+ "Valid options:",
+ " -h, --help",
+ "\t\tShow this help menu.",
+ " -l, --logfile <path>",
+ "\t\tRedirect logging to file.",
+ " -v, --verbose",
+ "\t\tInclude warning (and errors) messages in log.",
+ " -vv, --vverbose",
+ "\t\tInclude information (and above) messages in log.",
+ " -vvv, --vvverbose",
+ "\t\tInclude debug (and above) messages in log.",
+ " -a, --append",
+ "\t\tAppend to logfile instead of truncating it",
+ "(if logging to a file)."]))
for mod_name, mod_desc in tool_modules:
_usage_module(mod_name, mod_desc)
@@ -134,14 +146,57 @@
sys.exit(exit_code)
+def setup_logging(log_file, verbosity, append):
+
+ level = {0: logging.ERROR,
+ 1: logging.WARNING,
+ 2: logging.INFO}.get(verbosity, logging.DEBUG)
+
+ if log_file is not None:
+ handler = logging.FileHandler(log_file, mode=(append and 'a' or 'w'))
+ else:
+ handler = logging.StreamHandler()
+ handler.setFormatter(logging.Formatter(
+ "%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::" +
+ "%(lineno)d::%(name)s::(%(funcName)s) %(message)s"))
+
+ root_logger = logging.getLogger('')
+ root_logger.setLevel(level)
+ root_logger.addHandler(handler)
+
+
def main():
load_modules()
try:
- opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
+ opts, args = getopt.getopt(sys.argv[1:], "hl:av",
+ ["help", "logfile=", "append",
+ "verbose", "vverbose", "vvverbose"])
except getopt.GetoptError:
usage_and_exit(1)
+ log_file = None
+ verbosity = 0
+ append = False
+
+ for opt in opts:
+ if opt[0] in ('-h', '--help'):
+ usage_and_exit(0)
+ elif opt[0] in ('-l', '--logfile'):
+ log_file = opt[1]
+ elif opt[0] in ('-v'):
+ verbosity += 1
+ elif opt[0] == '--verbose':
+ verbosity = 1
+ elif opt[0] == '--vverbose':
+ verbosity = 2
+ elif opt[0] == '--vvverbose':
+ verbosity = 3
+ elif opt[0] in ('-a', '--append'):
+ append = True
+
+ setup_logging(log_file, verbosity, append)
+
if len(args) < 1:
usage_and_exit(1)
--
To view, visit http://gerrit.ovirt.org/29421
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia495743f6e869f65843404e4d4c25c146ff14b43
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Dima Kuznetsov <dkuznets at redhat.com>
More information about the vdsm-patches
mailing list