Bonjour,
Comment faire pour rediriger les erreurs en utilisant le module logging.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python2.4
# -*- coding:Latin-1 -*-
 
import os
import logging
 
myFormat = "%(asctime)s %(threadName)-10s %(levelname)-8s %(message)s"
myFileName = "mylogging.log"
 
logging.basicConfig(level=logging.DEBUG,
            format=myFormat,
            filename=os.path.join(os.path.dirname(os.path.realpath(__file__)),myFileName),
            filemode="a")
 
logging.debug("Some debug")
logging.info("Some information")
logging.warning("Some warning")
logging.error("Some error")
 
## create an error
import moduleinexistant
Je voudrais que l'erreur ci dessous soit redirigée dans le fichier log plutôt qu'à l'écran.
Traceback (most recent call last):
File "./mylogging.py", line 21, in ?
import moduleinexistant
ImportError: No module named moduleinexistant
Merci par avance.