mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Better logging
This commit is contained in:
parent
f6af9697a9
commit
84ee96c394
3 changed files with 23 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
[general]
|
||||
status_path=~/.vdirsyncer/status/
|
||||
#verbose = False
|
||||
|
||||
[pair bob]
|
||||
# This syncronizes only a single collection/calendar/addressbook
|
||||
|
|
|
|||
|
|
@ -109,18 +109,17 @@ def _main(env, file_cfg):
|
|||
sys.exit(1)
|
||||
|
||||
@app.option('--verbose|-v')
|
||||
def verbose_option(context):
|
||||
'''Print generally more information.'''
|
||||
log.get('cli').setLevel(log.logging.DEBUG)
|
||||
sync_verbose_option(context)
|
||||
def verbose_option(context=None):
|
||||
'''Print more information.'''
|
||||
log.set_level(log.logging.DEBUG)
|
||||
|
||||
@app.option('--quiet|-q')
|
||||
def quiet_option(context=None):
|
||||
'''Inverse of --verbose.'''
|
||||
log.set_level(log.logging.WARNING)
|
||||
|
||||
sync_command = argvard.Command()
|
||||
|
||||
@sync_command.option('--verbose|-v')
|
||||
def sync_verbose_option(context):
|
||||
'''Print more information about the syncing process.'''
|
||||
log.get('sync').setLevel(log.logging.DEBUG)
|
||||
|
||||
@sync_command.main('[pairs...]')
|
||||
def sync_main(context, pairs=None):
|
||||
'''Syncronize the given pairs. If no pairs are given, all will be
|
||||
|
|
@ -150,4 +149,9 @@ def _main(env, file_cfg):
|
|||
action()
|
||||
|
||||
app.register_command('sync', sync_command)
|
||||
|
||||
if general.get('verbose', False):
|
||||
verbose_option()
|
||||
else:
|
||||
quiet_option()
|
||||
app()
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ import sys
|
|||
|
||||
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
default_level = logging.WARNING
|
||||
|
||||
|
||||
def create_logger(name):
|
||||
x = logging.getLogger(name)
|
||||
x.setLevel(logging.WARNING)
|
||||
x.setLevel(default_level)
|
||||
x.addHandler(stdout_handler)
|
||||
return x
|
||||
|
||||
|
|
@ -28,3 +29,10 @@ def get(name):
|
|||
if name not in loggers:
|
||||
loggers[name] = create_logger(name)
|
||||
return loggers[name]
|
||||
|
||||
|
||||
def set_level(level):
|
||||
global default_level
|
||||
default_level = level
|
||||
for logger in loggers.values():
|
||||
logger.setLevel(level)
|
||||
|
|
|
|||
Loading…
Reference in a new issue