Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add colors to logging output
Browse files Browse the repository at this point in the history
abbbi committed Oct 25, 2023
1 parent dfc5d39 commit 0056514
Showing 7 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ Version 1.9.45
---------
* virtnbdbackup: Add more info output during checkpoint handling, move
error message.
* Add colored output by default, option --nocolor to disable.

Version 1.9.44
---------
10 changes: 10 additions & 0 deletions libvirtnbdbackup/argopt.py
Original file line number Diff line number Diff line change
@@ -130,3 +130,13 @@ def addLogArgs(opt, prog):
type=str,
help="Path to Logfile (default: %(default)s)",
)


def addLogColorArgs(opt, prog):
"""Option to enable or disable colored output"""
opt.add_argument(
"--nocolor",
default=False,
help="Disable colored output (default: %(default)s)",
action="store_true",
)
3 changes: 3 additions & 0 deletions libvirtnbdbackup/common.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
from argparse import Namespace
from typing import Optional, List, Any, Union, Dict
from tqdm import tqdm
import coloredlogs

from libvirtnbdbackup import ssh
from libvirtnbdbackup.ssh.exceptions import sshError
@@ -96,6 +97,8 @@ def configLogger(
fileLog,
counter,
]
if args.nocolor is False:
coloredlogs.install()
if args.quiet is False:
handler.append(logging.StreamHandler(stream=sys.stderr))
if syslog is True:
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ lz4>=2.1.2
lxml
paramiko
typing_extensions
coloredlogs
1 change: 1 addition & 0 deletions virtnbdbackup
Original file line number Diff line number Diff line change
@@ -255,6 +255,7 @@ def main() -> None:
action="store_true",
help="Disable logging to stderr (default: %(default)s)",
)
argopt.addLogColorArgs(logopt, parser.prog)
debopt = parser.add_argument_group("Debug options")
debopt.add_argument(
"-q",
1 change: 1 addition & 0 deletions virtnbdmap
Original file line number Diff line number Diff line change
@@ -228,6 +228,7 @@ def main() -> None:
)
logopt = parser.add_argument_group("Logging options")
argopt.addLogArgs(logopt, parser.prog)
argopt.addLogColorArgs(logopt, parser.prog)
debopt = parser.add_argument_group("Debug options")
debopt.add_argument(
"-r",
1 change: 1 addition & 0 deletions virtnbdrestore
Original file line number Diff line number Diff line change
@@ -659,6 +659,7 @@ def main() -> None:
argopt.addRemoteArgs(remopt)
logopt = parser.add_argument_group("Logging options")
argopt.addLogArgs(logopt, parser.prog)
argopt.addLogColorArgs(logopt, parser.prog)
debopt = parser.add_argument_group("Debug options")
argopt.addDebugArgs(debopt)

0 comments on commit 0056514

Please sign in to comment.