This will help to secure the sensitive secrets, token, api keys, etc from logger.
As we know there is security issue when we include the sensitive information to the logger in case logger got leaked/hacked.
Before:
```
INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=abcdefg&width=20&heigh20"
```
After:
```
INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=********&width=20&heigh20"
```
It took me some time to figure out how to set up logging in Django. What I want to do is to log to a pair of rotating files each 1MB in size.
What I come up with is this code segment in the `settings.py` file.
This is a simple logging [filter](https://docs.djangoproject.com/en/1.5/topics/logging/#topic-logging-parts-filters) to ensure that user-entered passwords aren't recorded in the log or emailed to admins as part of the request data if an error occurs during registration/login.
Simple logging middleware that captures the following:
* remote address (whether proxied or direct)
* if authenticated, then user email address
* request method (GET/POST etc)
* request full path
* response status code (200, 404 etc)
* content length
* request process time
* If DEBUG=True, also logs SQL query information - number of queries and how long they took
This small decorator will trace the execution of your code every time it enters or exits a decorated function (by thread) and will insert appropriate indent into the log file along with exception information.
Prevents error flooding on high traffic production sites. Particularly useful to prevent clogging email servers etc.
See [discussion](http://groups.google.com/group/django-developers/browse_thread/thread/1dabc9139dd750ca/1d86fdca23189a7d?lnk=gst&q=error#1d86fdca23189a7d) and [closed ticket](http://code.djangoproject.com/ticket/11565).
Uses memcache if it can, or falls back to local, in-process memory where unavailable (down, etc).
Tweak to your needs using setting ERROR_RATE_LIMIT (seconds).
Requires Django 1.3+ or trunk r13981+
Simple logging decorator. Logs the function name along with the message.
`Jul 14 16:10:42 mtzion test_func: 1 two`
Define SYSLOG_FACILITY in settings.py.
import syslog
SYSLOG_FACILITY = syslog.LOG_LOCAL1
This will use the syslog system to log your logs. This is usefull when you use WSGI and want to have a per day logging file (TimedRotatingFileHandler is not process safe, and you may lose data when using it with WSGI).
Under a debian system, you'll have to modify **/etc/rsyslog.conf** and add:
local0.* -/var/log/django/django.log
local1.* -/var/log/django/payment.log
Middleware class logging request time to stderr.
This class can be used to measure time of request processing within Django. It can be also used to log time spent in middleware and in view itself, by putting middleware multiple times in INSTALLED_MIDDLEWARE.
Static method `log_message' may be used independently of the middleware itself, outside of it, and even when middleware is not listed in INSTALLED_MIDDLEWARE.
When running the Django development server, this middleware causes all executed SQL queries to get printed out to the console.
This is based on [Snippet 161](http://www.djangosnippets.org/snippets/161/). The big difference is that 161 logs by adding stuff to your response text, which isn't very convenient IMO.
The django_admin_log only logs changes, not simple requests.
Sometimes it can be useful to log when a user of your admin interface is checking out important data, for instance if you are making a system with personal sensitive data, that needs to comply with government / company policies.
This will log such hits to the django_admin_log by overriding the change_view method in ModelAdmin.
So you must override this method in all classes you want to have logged.