diff --git a/tools/virsh.c b/tools/virsh.c index def4c84f39..2b00579a00 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2326,10 +2326,9 @@ vshInitDebug(vshControl *ctl) debugEnv = getenv("VIRSH_LOG_FILE"); if (debugEnv && *debugEnv) { ctl->logfile = vshStrdup(ctl, debugEnv); + vshOpenLogFile(ctl); } } - - vshOpenLogFile(ctl); } /* @@ -2338,6 +2337,10 @@ vshInitDebug(vshControl *ctl) static bool vshInit(vshControl *ctl) { + /* Since we have the commandline arguments parsed, we need to + * re-initialize all the debugging to make it work properly */ + vshInitDebug(ctl); + if (ctl->conn) return false; @@ -3044,7 +3047,9 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) ctl->readonly = true; break; case 'l': + vshCloseLogFile(ctl); ctl->logfile = vshStrdup(ctl, optarg); + vshOpenLogFile(ctl); break; case 'e': len = strlen(optarg);