Created
September 5, 2013 09:03
-
-
Save toastdriven/6447761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For Django, at the bottom of ``settings.py`` after all your other settings... | |
# Setup a BoundLogger for the project/apps to use... | |
import structlog | |
structlog.BoundLogger.configure( | |
context_class=structlog.ThreadLocalDict(dict), | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Then within your views (or other code)... | |
import logging | |
from structlog import BoundLogger | |
log = BoundLogger.wrap(logging.getLogger(__name__)) | |
# Your views here... |
This is working with me with structlog==16.1.0
Anywhere at the bottom of the django settings.py
configure the structlog in the way you like, this is an example:
import structlog
structlog.configure(
processors=[
structlog.processors.JSONRenderer(sort_keys=True),
],
)
And anywhere in your code:
from structlog import wrap_logger
import logging
logger = wrap_logger(logger=logging.getLogger(__name__))
logger.warn('Event1')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, But I believe this is outdated now.