[IMP] config: deduplicate loggers in log_handler

Saving multiple levels for the same logger should work with few issues,
but over time pathological (basket) cases (e.g. using ``-s`` all the
time) may build pointlessly huge lists in their config file.

Only keep the last level for each logger when saving to a config file.
This commit is contained in:
Xavier Morel 2014-12-10 14:57:09 +01:00
parent 8641826ca4
commit e9f0d79f85
1 changed files with 14 additions and 1 deletions

View File

@ -623,7 +623,7 @@ class configmanager(object):
if opt in ('log_level',):
p.set('options', opt, loglevelnames.get(self.options[opt], self.options[opt]))
elif opt == 'log_handler':
p.set('options', opt, ','.join(self.options[opt]))
p.set('options', opt, ','.join(deduplicate_loggers(self.options[opt])))
else:
p.set('options', opt, self.options[opt])
@ -686,5 +686,18 @@ class configmanager(object):
config = configmanager()
def deduplicate_loggers(loggers):
""" Avoid saving multiple logging levels for the same loggers to a save
file, that just takes space and the list can potentially grow unbounded
if for some odd reason people use :option`odoo.py --save`` all the time.
"""
# dict(iterable) -> the last item of iterable for any given key wins,
# which is what we want and expect. Output order should not matter as
# there are no duplicates within the output sequence
return (
'{}:{}'.format(logger, level)
for logger, level in dict(it.split(':') for it in loggers).iteritems()
)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: