Project

General

Profile

0006-base-add-context-method-to-ProxyLogger-35818.patch

Benjamin Dauvergne, 05 Nov 2019 03:41 PM

Download (1.56 KB)

View differences:

Subject: [PATCH 06/11] base: add context method to ProxyLogger (#35818)

It copies the logger and add contextual informations to the extra dictionnary,
it overwrites keys from previous calls to context.
 passerelle/base/models.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
passerelle/base/models.py
755 755

  
756 756

  
757 757
class ProxyLogger(object):
758
    extra = None
758 759

  
759 760
    def __init__(self, connector):
760 761
        self.connector = connector
......
764 765
        self._logger = logging.getLogger(logger_name)
765 766
        self._logger.setLevel(connector.log_level)
766 767

  
768
    def context(self, **kwargs):
769
        proxy_logger_copy = copy.copy(self)
770
        proxy_logger_copy.extra = dict(self.extra or {}, **kwargs)
771
        return proxy_logger_copy
772

  
767 773
    @property
768 774
    def level(self):
769 775
        return self._logger.getEffectiveLevel()
......
805 811
            attr['appname'] = self.appname
806 812
            attr['slug'] = self.slug
807 813

  
808
            extra = kwargs.get('extra', {})
814
            extra = self.extra or {}
815
            extra.update(kwargs.get('extra', {}))
809 816
            request = extra.get('request')
810 817

  
811 818
            def is_json_serializable(value):
812
-