Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Using with the logging module. #214

Closed
aroberge opened this issue May 21, 2021 · 3 comments
Closed

Using with the logging module. #214

aroberge opened this issue May 21, 2021 · 3 comments
Labels
usability Making documentation or program easier to use.

Comments

@aroberge
Copy link
Owner

aroberge commented May 21, 2021

During a recent PFPy meeting, a question has been raised about using with the logging module. Following a previous suggestion that was made to me during a PyConUS discussion, I was already planning to investigate capturing and processing Warnings with the logging module (https://docs.python.org/3/library/logging.html#logging.captureWarnings), thus enhancing friendly using the logging module. However, I had not thought about the reverse, that is using friendly to supplement the logging module.

At the time, I mentioned that that this might simply require to use friendly.install(), but at the very least, I need to confirm this and add a section to the documentation. However, it might require more than this, for example, using the redirect="capture" option togther with some special function of the logging module.

So, briefly:

  1. figure out how to make friendly work with the logging module
  2. add a section to the documentation.
@aroberge aroberge added the usability Making documentation or program easier to use. label May 21, 2021
@aroberge
Copy link
Owner Author

Here's a first example:

import friendly
import logging

logging.basicConfig(filename="ignore.log")
friendly.set_lang('fr')

a = 1
b = 0
try:
    c = a / b
except Exception:
    friendly.explain_traceback(redirect="capture")
    result = friendly.get_output()
    logging.error(result)

And here's the output file

ERROR:root:
Traceback (most recent call last):
  File "ignore.py", line 10, in <module>
    c = a / b
ZeroDivisionError: division by zero

    Une exception de type `ZeroDivisionError` se produit lorsque vous essayez de diviser une valeur
    par zéro soit directement ou en utilisant une autre opération mathématique.
    
    Vous divisez par le terme suivant
    
         b
    
    qui est égal à zéro.
    
    Exception levée à la ligne 10 du fichier ignore.py.
    
        8: b = 0
        9: try:
    -->10:     c = a / b
                   ^^^^^
       11: except Exception:

            a:  1
            b:  0

@AlvesInfo
Copy link

génial, c'est tout à fait ça!
Mercii!!

@aroberge
Copy link
Owner Author

@AlvesInfo J'ai rajouté une section dans la documentation (en anglais) avec une explication supplémentaire qui pourrait être utile.
Le lien est le suivant: https://aroberge.github.io/friendly-traceback-docs/docs/html/usage.html#logging

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
usability Making documentation or program easier to use.
Projects
None yet
Development

No branches or pull requests

2 participants