Skip to content

Commit

Permalink
feat: Add log path global option
Browse files Browse the repository at this point in the history
Also enable logger only if log path or level is specified.
  • Loading branch information
pawamoy committed Oct 15, 2019
1 parent 3407848 commit 7103e0b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/aria2p/cli.py
Expand Up @@ -40,7 +40,16 @@ def main(args=None):
args = parser.parse_args(args=args)
kwargs = args.__dict__

enable_logger(level=kwargs.pop("log_level"))
log_level = kwargs.pop("log_level")
log_path = kwargs.pop("log_path")

if log_path:
log_path = Path(log_path)
if log_path.is_dir():
log_path = log_path / "aria2p-{time}.log"
enable_logger(sink=log_path, level=log_level or "WARNING")
elif log_level:
enable_logger(sink=sys.stderr, level=log_level)

logger.debug("Checking arguments")
check_args(parser, args)
Expand Down Expand Up @@ -147,11 +156,14 @@ def get_parser():
"-L",
"--log-level",
dest="log_level",
default="WARNING",
default=None,
help="Log level to use",
choices=("TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"),
type=str.upper,
)
global_options.add_argument(
"-P", "--log-path", dest="log_path", default=None, help="Log path to use. Can be a directory or a file."
)

# ========= SUBPARSERS ========= #
subparsers = parser.add_subparsers(dest="subcommand", title="Commands", metavar="", prog="aria2p")
Expand Down

0 comments on commit 7103e0b

Please sign in to comment.