mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +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]
|
[general]
|
||||||
status_path=~/.vdirsyncer/status/
|
status_path=~/.vdirsyncer/status/
|
||||||
|
#verbose = False
|
||||||
|
|
||||||
[pair bob]
|
[pair bob]
|
||||||
# This syncronizes only a single collection/calendar/addressbook
|
# This syncronizes only a single collection/calendar/addressbook
|
||||||
|
|
|
||||||
|
|
@ -109,18 +109,17 @@ def _main(env, file_cfg):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@app.option('--verbose|-v')
|
@app.option('--verbose|-v')
|
||||||
def verbose_option(context):
|
def verbose_option(context=None):
|
||||||
'''Print generally more information.'''
|
'''Print more information.'''
|
||||||
log.get('cli').setLevel(log.logging.DEBUG)
|
log.set_level(log.logging.DEBUG)
|
||||||
sync_verbose_option(context)
|
|
||||||
|
@app.option('--quiet|-q')
|
||||||
|
def quiet_option(context=None):
|
||||||
|
'''Inverse of --verbose.'''
|
||||||
|
log.set_level(log.logging.WARNING)
|
||||||
|
|
||||||
sync_command = argvard.Command()
|
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...]')
|
@sync_command.main('[pairs...]')
|
||||||
def sync_main(context, pairs=None):
|
def sync_main(context, pairs=None):
|
||||||
'''Syncronize the given pairs. If no pairs are given, all will be
|
'''Syncronize the given pairs. If no pairs are given, all will be
|
||||||
|
|
@ -150,4 +149,9 @@ def _main(env, file_cfg):
|
||||||
action()
|
action()
|
||||||
|
|
||||||
app.register_command('sync', sync_command)
|
app.register_command('sync', sync_command)
|
||||||
|
|
||||||
|
if general.get('verbose', False):
|
||||||
|
verbose_option()
|
||||||
|
else:
|
||||||
|
quiet_option()
|
||||||
app()
|
app()
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,12 @@ import sys
|
||||||
|
|
||||||
|
|
||||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||||
|
default_level = logging.WARNING
|
||||||
|
|
||||||
|
|
||||||
def create_logger(name):
|
def create_logger(name):
|
||||||
x = logging.getLogger(name)
|
x = logging.getLogger(name)
|
||||||
x.setLevel(logging.WARNING)
|
x.setLevel(default_level)
|
||||||
x.addHandler(stdout_handler)
|
x.addHandler(stdout_handler)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
@ -28,3 +29,10 @@ def get(name):
|
||||||
if name not in loggers:
|
if name not in loggers:
|
||||||
loggers[name] = create_logger(name)
|
loggers[name] = create_logger(name)
|
||||||
return loggers[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