Created
May 28, 2011 18:40
-
-
Save gennad/997114 to your computer and use it in GitHub Desktop.
Python logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logging.basicConfig(filename='example.log', level=logging.DEBUG) | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.DEBUG) | |
# create console handler and set level to debug | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.DEBUG) | |
# create formatter | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
# add formatter to ch | |
ch.setFormatter(formatter) | |
# add ch to logger | |
logger.addHandler(ch) | |
class CalibrationCanvas: | |
def draw(self): | |
logger.debug('CalibrationCanvas.draw') | |
# do some funky stuff | |
# ... | |
def update(self, model): | |
if not model: | |
logger.warning('update: No model specified') | |
cc = CalibrationCanvas() | |
cc.draw() | |
cc.update(None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment