1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import os.path
- import logging
- import logging.config
- try:
- from raven import Client
- from raven.handlers.logging import SentryHandler
- from raven.conf import setup_logging
- HAVE_SENTRY = True
- except ImportError:
- HAVE_SENTRY = False
- LOG_CONFIG = {
- "version": 1,
- "disable_existing_loggers": True,
- "formatters": {
- "console": {
- "format": "[%(asctime)s][%(levelname)s] %(name)s "
- "%(filename)s:%(funcName)s:%(lineno)d | %(message)s",
- "datefmt": "%H:%M:%S",
- }
- },
- "handlers": {
- "console": {
- "level": "DEBUG",
- "class": "logging.StreamHandler",
- "formatter": "console",
- },
- "file": {
- "level": "INFO",
- "class": "logging.FileHandler",
- "formatter": "console",
- "filename": os.path.expanduser("~/.piket_client.log"),
- },
- },
- "loggers": {
- "": {"handlers": ["console", "file"], "level": "INFO", "propagate": False},
- "piket_client": {"level": "INFO", "propagate": True},
- },
- }
- if HAVE_SENTRY and os.environ.get("SENTRY_DSN"):
- LOG_CONFIG["handlers"]["sentry"] = {
- "level": "ERROR",
- "class": "raven.handlers.logging.SentryHandler",
- "dsn": os.environ.get("SENTRY_DSN"),
- }
- LOG_CONFIG["loggers"][""]["handlers"].append("sentry")
- logging.config.dictConfig(LOG_CONFIG)
|