logging exceptions

43 views
Skip to first unread message

Yebach

unread,
Jan 28, 2015, 7:18:32 AM1/28/15
to web...@googlegroups.com
Hello

In my app I have a lot of functions with try: exception: 

What would be the best way to catch and log exceptions in a file ?

thank you 

Leonel Câmara

unread,
Jan 28, 2015, 7:41:26 AM1/28/15
to web...@googlegroups.com
You can use logging.exception('got exception')

However, try/exception is generally a bad practice, that catches at any exception at all and can lead to very weird bugs.

Vid Ogris

unread,
Jan 28, 2015, 8:00:20 AM1/28/15
to web...@googlegroups.com
where do I put logging.exception('got exception') and where do I set file path and name?

2015-01-28 13:41 GMT+01:00 Leonel Câmara <leonel...@gmail.com>:
You can use logging.exception('got exception')

However, try/exception is generally a bad practice, that catches at any exception at all and can lead to very weird bugs.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/R3O3Baig5Iw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


Leonel Câmara

unread,
Jan 28, 2015, 8:22:46 AM1/28/15
to web...@googlegroups.com
In your models you should have something like this:

import logging
logger = logging.getLogger("web2py.app." + request.application)
logger.setLevel(logging.DEBUG)

Then you can put logger.exception inside the exception block like so:

try:
    ...
exception:
    logger.exception('got exception')

As for the file you need to configure web2py logging by creating a "logging.conf" in your web2py's main directory (not the applications directory, web2py's root directory).
Reply all
Reply to author
Forward
0 new messages