Created
April 25, 2011 17:34
-
-
Save gregglind/940863 to your computer and use it in GitHub Desktop.
centralized logging
This file contains hidden or 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
"""use get_logger: | |
from this_logging import get_logger; logger = get_logger(__name__) | |
# then you can: | |
logger.debug("foo") | |
# and if you want to change the logging level: | |
import logging | |
logger.parent.setLevel(logging.DEBUG) | |
""" | |
from os.path import dirname, join, exists | |
import logging | |
import logging.config | |
logging_conf = join(dirname(__file__), 'logging.conf') | |
if exists(logging_conf): | |
logging.config.fileConfig(logging_conf) | |
else: | |
import sys | |
# i'd prefer funcName to lineno, but not available until 2.5 | |
fmt = "%(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s:%(lineno)d] %(message)s" | |
logging.basicConfig(stream=sys.stderr, level=logging.WARNING, format=fmt) | |
get_logger = logging.getLogger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment