1. Andriy Kornatskyy
  2. wheezy.caching

Commits

Andriy Kornatskyy  committed e0cbee6

Added support for key encode to one pass logger; default to sha1 hash encode.

  • Participants
  • Parent commits 6b6acd1
  • Branches default

Comments (0)

Files changed (1)

File src/wheezy/caching/logging.py

View file
  • Ignore whitespace
 """ `logging` module.
 """
 
+from hashlib import sha1
+
 from wheezy.caching.comp import __import__
+from wheezy.caching.encoding import hash_encode
 from wheezy.caching.utils import total_seconds
 
 
         handler once per one pass duration.
     """
 
-    def __init__(self, inner, cache, time, namespace=None):
+    def __init__(self, inner, cache, time, key_encode=None, namespace=None):
         """ Initialize the instance with the inner logging handler,
-            cache to use, time to keep lock and namespace.
+            cache to use, time to keep lock, key encode and namespace.
         """
         super(OnePassHandler, self).__init__()
         self.inner = inner
         self.cache = cache
         self.time = total_seconds(time)
+        self.key_encode = key_encode or hash_encode(sha1)
         self.namespace = namespace
 
     def emit(self, record):
         """ Emit a record. Use log record message as a key in cache.
         """
-        key = record.getMessage()
+        key = self.key_encode(record.getMessage())
         if self.cache.add(key, record.created, self.time, self.namespace):
             self.inner.emit(record)