Last active
February 23, 2019 17:52
-
-
Save ozcanyarimdunya/aa6f7b1aa079d7567e6c55c1e6749f01 to your computer and use it in GitHub Desktop.
python logger snippet
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 | |
from models import Person | |
fmt = "[%(asctime)s]:%(levelname)s:line,%(lineno)d:%(module)s:%(funcName)s: %(message)s" | |
lvl = logging.DEBUG | |
logging.basicConfig(level=lvl, format=fmt) | |
logger = logging.getLogger() | |
logger.debug("Hello") | |
p = Person(name="Ozcan") | |
p.say() | |
try: | |
logger.info("Dividing 1 with 0") | |
1/0 | |
except Exception as ex: | |
logger.exception(ex) | |
logger.info("Logger continue") | |
logger.error("What is life?") |
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 | |
logger = logging.getLogger() | |
class Person(object): | |
"""docstring for Person""" | |
def __init__(self, name): | |
self.name = name | |
def say(self): | |
logger.debug("Hello " + self.name) | |
try: | |
a = {} | |
c = a['Hello'] | |
except KeyError: | |
logger.exception("Hello not found") | |
return 4 |
Author
ozcanyarimdunya
commented
Feb 23, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment