Logging of full trace with Debug set to False

100 views
Skip to first unread message

Kevin Olbrich

unread,
Jan 28, 2019, 5:53:55 AM1/28/19
to Django users
Hi!

I would like to catch and send all exceptions to a logging system.
When Debug is set to False, all debug related information is lost (just a HTTP 500 error message).

While Debug False works perfectly in production, I would like to log and send the exceptions to a backend, where I can save them.
This would allow me to fix bugs, that only occur once every month (because nobody is able to reproduce).

Similar approach was the case with Testflight on iOS, where I got a message for every App-crash.

How can I handle this?

Kind regards
Kevin

Michal Petrucha

unread,
Jan 28, 2019, 6:20:35 AM1/28/19
to Django users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi Kevin,

You can set up your backend logging to send logs to Sentry [1], for
example. You can either set up your own Sentry instance, or use the
commercial offering [2]. If you set up sentry as one of the default
logging handlers, it will catch all unhandled exceptions, and you'll
get a fancy stack trace for each, including the values of local
variables in each stack frame.

Cheers,

Michal


[1]: https://github.com/getsentry/sentry
[2]: https://sentry.io/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJcTuVkAAoJEHA7T/IPM/kl5skQAOVvT+gu33Cn9YuM5152LaN/
hO8jQ5qC85k62+Z+3ptx8xsLOSPpbivdrAWOEW2asgRUFpSzdvsvDpF5ARWUlO9D
3s7bTfNqnPATDjEdiBep4ZQd5eWtkw7aMhHOS6gnwl60zEqlH62MIqOj9NFRL5YV
MMsCTAnqcB2IqXsiGmpxUvc5c20WHac4ODwOkOBAY4CPd1O6s1bf44LtD2bTaJTR
py7KvwKJ+4wkhM89cjnP5etIhdsnPbv+hKry40rji/J/k8VAz2w702jnRc5W6a8d
mPlBYfdZS/tfnNDx+TO+fKgwny1xrrE55vXabVgyt3nQF+KQluf2Zw2Q4HzDhhZ+
6L0QU2xR+EzFHsXCdhUAVF9+0h6guJzNQ7qsSz9KlZoGB5a2Jdk8Q4ji/RBVaORx
GEZpRw/VWTn7/mLvCdOxOH8J/IMf9avyEm+CK8K23BMFqO7ydmtUIboN/MVQ1UJA
4Xjp3vm1zB5hcaS9AjAJ5/vn9ySPjE9deoBxqUuN7I30Vug/EqqDhBhqOCiiwp4p
V6OwPMqhhZig3cvmigvwhZoT+WXUQwrGAGodleBon8ajIUcB1dxyxbPnbeIzSKPg
9lNot8WLlQEwYN7HWVQRMTc0NtLRg4YTI7UZWcwAneznxrCwKyzdQV3PhiN5A1Kh
VRcuK/Cf70seqQEarfXL
=HFoa
-----END PGP SIGNATURE-----

Anirudh Jain

unread,
Jan 28, 2019, 7:25:17 AM1/28/19
to django...@googlegroups.com
You  can setup a logging and debugging logging system using gunicorn in production using flags :-

--log-level debug
--access-logfile /home/ubuntu/websitelogs.log

For more setting options read gunicorn documentation 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20190128112004.GD10973%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Kevin Olbrich

unread,
Jan 28, 2019, 7:42:01 AM1/28/19
to Django users
Hi Michal,

looks very promissing. I read the SDK guide for Django and I realy like it.
Thank you!

Kevin

Kevin Olbrich

unread,
Jan 28, 2019, 7:45:44 AM1/28/19
to Django users
Hi Anirudh,

I am using uWSGI and not Gunicorn. At least for uWSGI, with Debug = False, it only logs the HTTP status code but not exception (might be the same with Gunicorn).
I will try Sentry which provides a clean GUI and notification of new problems. This also seems to work for my Celery tasks and Django admin commands.

Thank you very much for your reply!

Kevin

Michal Petrucha

unread,
Jan 28, 2019, 7:55:29 AM1/28/19
to Django users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Mon, Jan 28, 2019 at 04:45:44AM -0800, Kevin Olbrich wrote:
> Hi Anirudh,
>
> I am using uWSGI and not Gunicorn. At least for uWSGI, with Debug = False,
> it only logs the HTTP status code but not exception (might be the same with
> Gunicorn).
> I will try Sentry which provides a clean GUI and notification of new
> problems. This also seems to work for my Celery tasks and Django admin
> commands.

Since you're mentioning Celery, I thought it might be worth mentioning
that Celery performs some black magic ritual on the Python logging
config in its default configuration, which interferes with the way
Sentry handles errors – or at least that's been my experience. At one
point I noticed that errors happening inside Celery tasks didn't have
all the stack values, like ones from the regular request/response had.
I don't remember exactly how, and I don't have access to that code
base anymore, but I remember that we had to explicitly disable as much
of Celery's custom logging as we could in order to get that to work.
(Might be that things have improved since then, though.)

Good luck,

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJcTvuFAAoJEHA7T/IPM/kltD8P/0MfET5/KylfZM/BWHDz4+vn
8U7hr4Zraz5R+zzr4yq7Ow0tom4zWE0EqpYREv87A4tX7dHGITTQLbU+bCce/MNQ
tIVD2D498XsEBGRsNav0kOr6ATuWoPuJlLLSFYGbGHedCKz6UB+ftmwYhL7WOQgr
zE8LeLS37jbm02/z6DD25intYUpRbKeeSRjyqkc+6esUz2IAXVQQ1NcUtJjPbmvi
zJtyWUX/RXS3Wulrp8lwLJ7rThcFAh3wVmC/nJCHeBQFLDmmLZx08EEnV1w7uxwv
AcowzfrGPOYv7VcOK9K9KvUPCrIj3KovU4DPlffuX6xxy8FZTvIyDptJAaMnh9C+
i8So48kPL1TxBk1lPuWx8TLr+RR1y4LIy7KVwMgRyeFC5zGIdBiAFIwo9X5utdc9
1uuO07bGn9224vpk87zyizA8Q88Qeee7kco+a0v0f8+Xxz6oAKg9uf3broJ9nl99
jp6Pp9QTzlpYFnw0bjMDMI3KRLkAxbWmeuGtBt7tELKFfHoae3RtfCqNitvEhN07
rz44xC2dbwPvQdV2UMElX+jS9omk+8oEwgMNvOPXyAsf3NexwcuN0lzoo5MS2OpY
kkwbNCD0aeHtreY5BJrXgONmXd58OswZhsCbcvZXqhIJ1MxreCzasXVvF7ZNHp6z
daRHSphHWV6/sDLFFfGw
=6WLZ
-----END PGP SIGNATURE-----

Kevin Olbrich

unread,
Jan 29, 2019, 5:27:49 AM1/29/19
to Django users
Hi!

Seems like things were improved since then:

There is an integration that I can enable which should take care of things.

I realy like Sentry. Currently I use the free tier while I check how to setup my own node.
Some of my Apps already send Exceptions (broke some things to test it).

Thanks for the hint to this excellent tool!

Kevin
Reply all
Reply to author
Forward
0 new messages