Lets say I want to log like this formatting string :
%(levelname)s %(asctime)s %(module)s %(funcName)s %(message)s %(user_id)
It can be done using this type of logging command :
logging.error('Error fetching information', extra = { 'user_id': 22 } )
This will add the current userid to logging messages for current request.
But the extra dict needs to be added to every logging call.
Is there a good way to add this context in a common function in django (eg Middleware, or index function of a view ), so that the extra dictionary with user id is set, and all further logging calls in the current request also log the current user.