Rework logging/verbosity system #90
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch ":master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request re-engineers the logging/verbosity system.
verbosity
is removed as an function argument. Instead a logger is acquired withlogger = logging.getLogger(__name__)
which is then used like-v 1
to INFO,-v 2
to DEBUGINFO
. It wasWARNING
before, but think it's more on the safe side. If confused, better print too much logging than too little.insert_logging_mock
.== Remarks ==
--filter AME
,--stat
. Everything in good faith, but borgmatic output won't be exactly the same.isEnabledFor(DEBUG)
is true,isEnabledFor(INFO)
is also true.--filter AME
is enabled for logging DEBUG and INFO.--debug --info
, I let the latter option overwrite the first.I appreciate your comments and hope we can work towards a merge into master!
Awesome, thanks for taking on refactor of this scope! Don't forget to add yourself to AUTHORS if you like. And feel free to update NEWS (or I'd be happy to do that).
@ -154,3 +151,1 @@
VERBOSITY_SOME: ('--info',) if dry_run else ('--info', '--stats'),
VERBOSITY_LOTS: ('--debug', '--list', '--show-rc') if dry_run else ('--debug', '--list', '--show-rc', '--stats'),
}.get(verbosity, ())
+ (('--list', '--filter', 'AME', '--info', '--stats') if logger.isEnabledFor(logging.INFO) else ())
You'll need to retain the logic that omits
--stats
during a dry run, because--stats
and--dry-run
can't be specified together. More info here: https://borgbackup.readthedocs.io/en/stable/usage/create.html#description@ -155,2 +151,2 @@
VERBOSITY_LOTS: ('--debug', '--list', '--show-rc') if dry_run else ('--debug', '--list', '--show-rc', '--stats'),
}.get(verbosity, ())
+ (('--list', '--filter', 'AME', '--info', '--stats') if logger.isEnabledFor(logging.INFO) else ())
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
Does that mean Borg just ignores the
--info
and respects only the--debug
flag?Made it all the way through. Generally looks great. See minor feedback throughout!
@ -59,2 +55,2 @@
VERBOSITY_LOTS: ('--debug', '--stats', '--list', '--show-rc'),
}.get(verbosity, ())
+ (('--stats',) if logger.isEnabledFor(logging.INFO) else ())
+ (('--info',) if logger.isEnabledFor(logging.INFO) else ())
Any reason not to combine these two lines?
@ -93,3 +93,3 @@
'-v', '--verbosity',
type=int,
help='Display verbose progress (1 for some, 2 for lots)',
help='Display verbose progress (1 for INFO, 2 for DEBUG)',
Might be nice to leave these as "some" and "lots", if only because not all users are Python programmers, and so won't necessarily be familiar with Python log levels. (I don't feel strongly about this.)
@ -122,3 +122,3 @@
checks.
'''
logger.info('{}: Parsing configuration file'.format(config_filename))
logger.debug('{}: Parsing configuration file'.format(config_filename))
Any reason for the switch to
debug
here? I think the idea with it beinginfo
is that you could easily see what borgmatic is doing with just the first (-v 1
) verbosity level. Especially useful if you've got multiple configuration files and you want to see what's being done for each.@ -20,0 +19,4 @@
def insert_logging_mock(log_level):
logging = flexmock(module.logging.Logger)
logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level)
Super minor: It'd be great to use a more descriptive variable than just
x
here. Similar elsewhere this pattern occurs.@ -23,1 +23,4 @@
def insert_logging_mock(log_level):
logging = flexmock(module.logging.Logger)
logging.should_receive('isEnabledFor').replace_with(lambda x : x >= log_level)
Given that this occurs several times, you could factor it out into a common test file. For instance, the existing
borgmatic/tests/unit/test_verbosity.py
might be a good candidate.@ -9,3 +9,3 @@
def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():
assert module.verbosity_to_log_level('my pants') == logging.WARNING
assert module.verbosity_to_log_level('my pants') == logging.INFO
Note that the name of this test function is now incorrect!
@ -13,3 +13,3 @@
VERBOSITY_SOME: logging.INFO,
VERBOSITY_LOTS: logging.DEBUG,
}.get(verbosity, logging.WARNING)
}.get(verbosity, logging.INFO)
Does this mean that if you omit
-v
/--verbosity
from the borgmatic command-line, you'll know getINFO
logs instead ofWARNING
? So now you'll get a fair amount of log spew whereas before it was pretty silent. That seems a little unexpected unless-v
/--verbosity
is specified. What's your thinking there?Not really. Done.
Yeah, already had this on my agenda. Done now.
Done. Also added an assertion to the previous function to test that
VERBOSTIY_LOTS
maps toDEBUG
.INFO and DEBUG are pretty much universal for log levels. But I am fine and have changed it back to some and lots. Done.
Oh, wasn't aware of that, done.
Exactly. Unfortunately I am not sure if this is documented behavior of borg or python argparse. I think best will be to ask borg's mailing list. Even cooler would be to not call the borg executable, but use a python API. But that leads us too far... ;-)
Done.
Definitely a matter of taste here. Switched it back to info, as you proposed.
Ok, just pushed a commit that should address most of the issues.
AFAIK, issues left are
Default log level, when no --verbosity parameter is specified, was WARNING (almost silent) now INFO.
Can we rely that --debug overwrites a preceding --info parameter.
Anything I forgot?
Thanks for making all the changes!
@ -155,2 +151,2 @@
VERBOSITY_LOTS: ('--debug', '--list', '--show-rc') if dry_run else ('--debug', '--list', '--show-rc', '--stats'),
}.get(verbosity, ())
+ (('--list', '--filter', 'AME', '--info') if logger.isEnabledFor(logging.INFO) else ())
+ (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ())
If you wanted to avoid relying on the undocumented behavior (
--debug
overriding--info
), one idea is that you could break out the construction of flags to a separateif
/elif
similar to the code elsewhere. For instance, something like:Another option would be to use
getEffectiveLevel()
instead ofisEnabledFor()
to sidestep falling through the hierarchy fromDEBUG
toINFO
. That also has the side benefit of letting you keep things inline and non-imperative:Yup, I think those are the two remaining topics! I added some ideas above on how to tackle the second one.
I already thought about using
getEffectiveLevel
. I would use it only for--info
. More generally: only for parameters that should not be enabled at a higher log level.--debug
should also be enabled if the log level is even higher than debug (not used, but it should be possible).I have addressed this in the recent commit.
Looks great, thanks!
One more idea: I think the unit tests should be renamed from
to
?
Sure, that makes sense to me given all the changes.
Also, part of the motivation for the "almost silent" default verbosity: A big use case for borgmatic is running it regularly via cron. And if I recall correctly, by default the stock cron will just succeed silently if the command it's running has no output upon success t(sort of a Unix-y default), but will send email if the command has output on stdout/stderr.
Ok, reverted the default log level to WARNING, renamed the test functions and also some doc string that were still mentioning verbosity as a function argument.
I did not rename the
verbosity_flags
variable used in some functions. My idea is that flags that go to borg and influence the output behavior are still verbosity, while of course derived from borgmatic's log level. By calling them log level we would make assumptions of the inner workings of borg and also something like--show-rc
probably does not affect borg's log level.I also updated the NEWS file.
Is there anything left that stands between that PR and a merge? :-)
Looks great, merged! Thanks again for all your hard work here.