#19395 closed Cleanup/optimization (fixed)
Improve logging section by providing a SIMPLE example
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
New to Python and Django. We have been gifted with several Django sites to maintain. These sites are poorly written and have no debug capabilities, so i wanted to enable a primitive log to report on uncaught exceptions, as well as a place we can manually write to. I don't have all afternoon to work through all the permutations of Python logging; I just need the most basic. So, the fact that the only log config example you provided is humungous is disappointing.
I'm sure many would be grateful for a minimal single textfile logging example they can just cut'n'paste and use ASAP. Thanks.
Attachments (1)
Change History (10)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 12 years ago
Thanks to commenter for the suggestion re logbook ( http://packages.python.org/Logbook/ ). Our main requirement is for something to catch and report on _untrapped_ errors, so the built-in Python/Django logging is required.
comment:4 by , 12 years ago
I think it's unclear what a simple example would be. Logging to syslog, to stdout, ...?
The following is the logging code in settings.py
generated by (django-admin.py startproject ...
):
# A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } }
Is this a simple enough configuration to begin with?
Aside: For unhandled exception tracking, I think you should have a look at Sentry or Exceptional.
comment:5 by , 12 years ago
Thanks! Email notification would be a good starting point, especially for a live site. Me, I've always preferred a simple text log, especially at the development stage. I can't understand how people can develop without one, frankly, but that's just my opinion.
Here's what I ended up with, after spending some time in the Django docs:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file':{ 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': '/var/log/django/cotizador.log', } }, 'loggers': { 'django.request': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, } }
It seems to work, and is catching untrapped exceptions, but I'm sure it could be improved. The first things I'd add are the formatter with timestamp, and nightly file rollover.
I think that an example containing both the emailer instance and a simple textfile instance would help 99% of users get something working right away. Again, thanks.
by , 11 years ago
Attachment: | 19395.diff added |
---|
comment:6 by , 11 years ago
Has patch: | set |
---|
comment:7 by , 11 years ago
I don't think that which writes all logging to a local file
is true. all request logging
would be probably more correct.
comment:8 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I heard some people being very enthousiastic about logbook: http://packages.python.org/Logbook/ . Though that doesn't solve the docs, it might be worthwile to take a look on their website. They give an example right-away, and it is very clear.