Use variables VIRSH_DEBUG and VIRSH_LOG_FILE for controlling virsh logging.
Signed-off-by: Supriya Kannery <supriyak(a)in.ibm.com>
---
tools/virsh.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
Index: libvirt/tools/virsh.c
===================================================================
--- libvirt.orig/tools/virsh.c
+++ libvirt/tools/virsh.c
@@ -12150,9 +12150,31 @@ vshError(vshControl *ctl, const char *fo
static bool
vshInit(vshControl *ctl)
{
+ char *debugEnv;
+
if (ctl->conn)
return false;
+ if (ctl->debug == -1) {
+ /* log level not set from commandline, check env variable */
+ debugEnv = getenv("VIRSH_DEBUG");
+ if (debugEnv) {
+ if ((virStrToLong_i(debugEnv, NULL, 10, &ctl->debug) < 0) ||
+ (ctl->debug < VSH_ERR_DEBUG) || (ctl->debug >
VSH_ERR_ERROR)) {
+ vshError(ctl, "%s", _("VIRSH_DEBUG not set with a valid
numeric value"));
+ ctl->debug = VSH_ERR_DEBUG;
+ }
+ }
+ }
+
+ if (ctl->logfile == NULL) {
+ /* log file not set from cmdline */
+ debugEnv = getenv("VIRSH_LOG_FILE");
+ if (debugEnv && *debugEnv){
+ ctl->logfile = vshStrdup(ctl, debugEnv);
+ }
+ }
+
vshOpenLogFile(ctl);
/* set up the library error handler */
@@ -12248,14 +12270,15 @@ vshOutputLogFile(vshControl *ctl, int lo
*/
gettimeofday(&stTimeval, NULL);
stTm = localtime(&stTimeval.tv_sec);
- virBufferAsprintf(&buf, "[%d.%02d.%02d %02d:%02d:%02d %s] ",
+ virBufferAsprintf(&buf, "[%d.%02d.%02d %02d:%02d:%02d %s %d] ",
(1900 + stTm->tm_year),
(1 + stTm->tm_mon),
stTm->tm_mday,
stTm->tm_hour,
stTm->tm_min,
stTm->tm_sec,
- SIGN_NAME);
+ SIGN_NAME,
+ getpid());
switch (log_level) {
case VSH_ERR_DEBUG:
lvl = LVL_DEBUG;
@@ -12574,7 +12597,7 @@ vshUsage(void)
" options:\n"
" -c | --connect <uri> hypervisor connection
URI\n"
" -r | --readonly connect readonly\n"
- " -d | --debug <num> debug level [0-5]\n"
+ " -d | --debug <num> debug level [0-4]\n"
" -h | --help this help\n"
" -q | --quiet quiet mode\n"
" -t | --timing print timing information\n"
@@ -12840,6 +12863,7 @@ main(int argc, char **argv)
memset(ctl, 0, sizeof(vshControl));
ctl->imode = true; /* default is interactive mode */
ctl->log_fd = -1; /* Initialize log file descriptor */
+ ctl->debug = -1; /* Initiatize log level */
if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
ctl->name = vshStrdup(ctl, defaultConn);