Skip to content

Instantly share code, notes, and snippets.

@ozcanyarimdunya
Last active February 23, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozcanyarimdunya/aa6f7b1aa079d7567e6c55c1e6749f01 to your computer and use it in GitHub Desktop.
Save ozcanyarimdunya/aa6f7b1aa079d7567e6c55c1e6749f01 to your computer and use it in GitHub Desktop.
python logger snippet
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?")
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
@ozcanyarimdunya
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment