Skip to content

Commit

Permalink
Add log filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fmr committed Aug 5, 2014
1 parent 3e2654f commit cc0f010
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cid/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
import logging
from cid.locals import get_cid


class CidContextFilter(logging.Filter):

def filter(self, record):
record.cid = get_cid()
return True
31 changes: 31 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,36 @@ def pytest_configure():
),

# Other settings go here
LOGGING={
'version': 1,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(cid)s %(message)s' # noqa
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'filters': {
'cid': {
'()': 'cid.log.CidContextFilter'
}
},
'handlers': {
'cid': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'filters': ['cid']
}
},
'loggers': {
'cid': {
'handlers': ['cid'],
'propagate': True,
'level': 'DEBUG'
}
}
}
)
settings.configure(**BASE_SETTINGS)

0 comments on commit cc0f010

Please sign in to comment.