本文整理汇总了Python中raven.handlers.logging.SentryHandler方法的典型用法代码示例。如果您正苦于以下问题:Python logging.SentryHandler方法的具体用法?Python logging.SentryHandler怎么用?Python logging.SentryHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raven.handlers.logging
的用法示例。
在下文中一共展示了logging.SentryHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_plugins
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def init_plugins():
"""初始化日志、错误追踪、打点插件"""
from everyclass.rpc import init as init_rpc
from everyclass.common.flask import print_config
# Sentry
if plugin_available("sentry"):
sentry.init_app(app=__app)
sentry_handler = SentryHandler(sentry.client)
sentry_handler.setLevel(logging.WARNING)
logging.getLogger().addHandler(sentry_handler)
init_rpc(sentry=sentry)
logger.info('Sentry is inited because you are in {} mode.'.format(__app.config['CONFIG_NAME']))
# metrics
global statsd
statsd = DogStatsd(namespace=f"{__app.config['SERVICE_NAME']}.{os.environ.get('MODE').lower()}",
use_default_route=True)
init_rpc(logger=logger)
print_config(__app, logger)
示例2: _install_sentry
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def _install_sentry():
if "AVALON_SENTRY" not in Session:
return
try:
from raven import Client
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging
except ImportError:
# Note: There was a Sentry address in this Session
return log.warning("Sentry disabled, raven not installed")
client = Client(Session["AVALON_SENTRY"])
# Transmit log messages to Sentry
handler = SentryHandler(client)
handler.setLevel(logging.WARNING)
setup_logging(handler)
self._sentry_client = client
self._sentry_logging_handler = handler
log.info("Connected to Sentry @ %s" % Session["AVALON_SENTRY"])
示例3: init_logging
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def init_logging(level='INFO'):
root = logging.getLogger()
root.setLevel(0)
patch_gevent_hub_print_exception()
if State.config.get('sentry'):
hdlr = SentryHandler(raven.Client(State.config['sentry'], transport=GeventedHTTPTransport))
hdlr.setLevel(logging.ERROR)
root.addHandler(hdlr)
fmter = ServerLogFormatter()
hdlr = logging.StreamHandler(sys.stdout)
hdlr.setLevel(getattr(logging, level))
hdlr.setFormatter(fmter)
root.addHandler(hdlr)
root.info(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
root.info('==============================================')
示例4: __init__
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def __init__(self, bot):
self.bot = bot
self.settings = dataIO.load_json('data/sentry/settings.json')
if self.settings['dsn'] is None:
log.warning('Sentry: DSN key is not set. Not sending logs!')
else:
if self.settings['ssl'] is False:
self.raven = Client(self.settings['dsn'] + '?verify_ssl=0')
else:
self.raven = Client(self.settings['dsn'])
self.handler = SentryHandler(self.raven)
self.handler.setLevel(self.settings['level'])
self.logger = logging.getLogger("red").addHandler(self.handler)
setup_logging(self.handler)
# --- Raven settings
self.raven.tags = self.settings['tags']
if self.settings['name'] is not None:
self.raven.name = self.settings['name']
if self.settings['environment'] is not None:
self.raven.environment = self.settings['environment']
if self.settings.get('ignore'):
self.raven.ignore = self.settings['ignore']
示例5: init_app
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def init_app(self, app):
dsn = app.config.get('SENTRY_DSN')
if dsn:
config = app.config.get_namespace('SENTRY_')
self.client = raven.Client(**config)
handler = SentryHandler(self.client)
handler.setLevel(logging.ERROR)
setup_logging(handler)
try:
from raven.contrib.celery import (
register_signal, register_logger_signal)
register_logger_signal(self.client)
register_signal(self.client)
except ImportError:
pass
示例6: init_sentry
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def init_sentry():
"""
init sentry
:return:
"""
from raven import Client
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging
from complexconfig.configcontainer import configcontainer
config = configcontainer.get_config("sniffer")
enable = config.get_boolean("sniffer.sentry.enable", False)
if not enable:
return
sentry_level = config.get_string("sniffer.sentry.min_level", "error")
sentry_server_name = config.get_string("sniffer.sentry.server_name", "")
sentry_dsn = config.get_string("sniffer.sentry.dsn", "")
if not sentry_dsn or not sentry_server_name:
return
print_with_time("sentry is enabled with dsn: {}, server_name: {}, level: {}".format(sentry_dsn,
sentry_server_name,
sentry_level))
client = Client(sentry_dsn, name=sentry_server_name)
handler = SentryHandler(client)
if sentry_level.lower() == 'debug':
handler.level = logging.DEBUG
elif sentry_level.lower() == 'info':
handler.level = logging.INFO
else:
handler.level = logging.ERROR
setup_logging(handler)
示例7: load_sentry
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def load_sentry(self):
if self.clientid == "":
return
self.raven = Client(self.clientid, transport=AioHttpTransport)
self.handler = SentryHandler(self.raven)
setup_logging(self.handler)
log.debug("Sentry handler activated.")
示例8: setup_sentry
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def setup_sentry(dsn=None):
"""Configures the Sentry logging handler.
Args:
dsn - DSN for the Sentry project.
"""
handler = SentryHandler(dsn, level=logging.ERROR)
setup_logging(handler)
示例9: __init__
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def __init__(self, config=None):
self.config = {
'capture_timeout_warnings': boolval(os.environ.get('SENTRY_CAPTURE_TIMEOUTS', True)),
'timeout_warning_threshold': float(os.environ.get('SENTRY_TIMEOUT_THRESHOLD', 0.50)),
'capture_memory_warnings': boolval(os.environ.get('SENTRY_CAPTURE_MEMORY', True)),
'memory_warning_threshold': float(os.environ.get('SENTRY_MEMORY_THRESHOLD', 0.75)),
'capture_unhandled_exceptions': boolval(os.environ.get('SENTRY_CAPTURE_UNHANDLED', True)),
'auto_bread_crumbs': boolval(os.environ.get('SENTRY_AUTO_BREADCRUMBS', True)),
'capture_errors': boolval(os.environ.get('SENTRY_CAPTURE_ERRORS', True)),
'filter_local': boolval(os.environ.get('SENTRY_FILTER_LOCAL', True)),
'is_local': os.environ.get('IS_OFFLINE', False) or os.environ.get('IS_LOCAL', False),
'logging': boolval(os.environ.get('SENTRY_CAPTURE_LOGS', True)),
'log_level': extract_log_level_from_environment('SENTRY_LOG_LEVEL', logging.WARNING),
'enabled': boolval(os.environ.get('SENTRY_ENABLED', True)),
}
self.config.update(config or {})
# check for local environment
if self.config['filter_local'] and self.config['is_local']:
logger.warning('Sentry is disabled in local environment')
self.config["enabled"] = False
return
if self.config.get('raven_client'):
assert self.config.get('raven_client') and not isinstance(self.config.get('raven_client'), Client)
else:
self.config['raven_client'] = configure_raven_client(self.config)
if self.config['logging'] and self.config['raven_client']:
handler = SentryHandler(self.config['raven_client'])
handler.setLevel(self.config['log_level'])
setup_logging(handler)
示例10: server_log_handler
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def server_log_handler(client):
""" Adds sentry log handler to the logger
:return: the sentry handler
"""
from raven.handlers.logging import SentryHandler
sh = SentryHandler(client=client, level=logging.ERROR)
# Don't send Sentry events for command-line usage errors
old_emit = sh.emit
def emit(self, record):
if record.message.startswith("Command-line usage error:"):
return
return old_emit(record)
sh.emit = lambda x: emit(sh, x)
fmt = ("[%(asctime)s][%(levelname)s] %(filename)s: %(lineno)d | "
"%(message)s")
formatter = logging.Formatter(fmt=fmt, datefmt="%H:%M:%S")
formatter.converter = time.gmtime
sh.setFormatter(formatter)
logger.addHandler(sh)
return sh
# define class color
示例11: __init__
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def __init__(
self,
sentry_kwargs=None,
*,
install_excepthook=True,
loop=None,
patch_logging=False,
sentry_log_level=logging.ERROR
):
if sentry_kwargs is None:
sentry_kwargs = {}
sentry_kwargs = {
"transport": raven_aiohttp.AioHttpTransport,
"enable_breadcrumbs": False,
# by default, do not let raven.Client install its own excepthook
"install_sys_hook": not install_excepthook,
**sentry_kwargs,
}
self.client = raven.Client(**sentry_kwargs)
# Setup Sentry logger - https://docs.sentry.io/clients/python/integrations/#logging
if patch_logging:
handler = SentryHandler(client=self.client)
handler.setLevel(sentry_log_level)
setup_logging(handler)
if install_excepthook:
self.update_excepthook(loop)
示例12: __init__
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def __init__(self, dsn):
if dsn:
# ref: https://blog.windrunner.me/tool/sentry.html#%E5%92%8C-scrapy-%E9%9B%86%E6%88%90
handler = SentryHandler(dsn)
handler.setLevel(logging.ERROR)
setup_logging(handler)
示例13: setup_logging
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def setup_logging(log_name, debug=False, filepath=None, sentry_dsn=None,
file_lvl="INFO", sentry_lvl="WARN"):
"""Setup logging according to the specified options. Return the Logger
object.
"""
fmt = logging.Formatter(
'%(asctime)s [%(process)d] %(levelname)s %(message)s'
)
stream_handler = logging.StreamHandler()
if debug:
stream_log_level = logging.DEBUG
file_log_level = logging.DEBUG
else:
stream_log_level = logging.CRITICAL
file_log_level = getattr(logging, file_lvl)
logger = logging.getLogger(log_name)
logger.setLevel(file_log_level)
stream_handler.setLevel(stream_log_level)
stream_handler.setFormatter(fmt)
logger.addHandler(stream_handler)
if filepath:
file_handler = logging.FileHandler(filepath)
file_handler.setLevel(file_log_level)
file_handler.setFormatter(fmt)
logger.addHandler(file_handler)
if sentry_dsn and _HAS_RAVEN:
sentry_level = getattr(logging, sentry_lvl)
sentry_handler = SentryHandler(sentry_dsn)
sentry_handler.setLevel(sentry_level)
logger.addHandler(sentry_handler)
return logger
示例14: init_app
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def init_app(self, app: sanic.Sanic):
self.client = raven.Client(
dsn=app.config.get('SENTRY_DSN', None),
transport=raven_aiohttp.AioHttpTransport,
**app.config.get('SENTRY_PARAMS', {})
)
self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
logger.addHandler(self.handler)
self.app = app
self.app.sentry = self
示例15: check_args
# 需要导入模块: from raven.handlers import logging [as 别名]
# 或者: from raven.handlers.logging import SentryHandler [as 别名]
def check_args(self, args):
# check allow_other and allow_root
if args.allow_other:
args.allow_root = False
else:
args.allow_root = True
# check log_level
if args.debug:
args.log_level = "debug"
# setup logging
if args.log != "syslog":
if args.log in ("-", "/dev/stdout"):
handler = StreamHandler(sys.stdout)
else:
handler = TimedRotatingFileHandler(args.log, when="midnight")
handler.setFormatter(
Formatter(
fmt="%(asctime)s %(threadName)s: " "%(message)s",
datefmt="%B-%d-%Y %H:%M:%S",
)
)
else:
if sys.platform == "darwin":
handler = SysLogHandler(address="/var/run/syslog")
else:
handler = SysLogHandler(address="/dev/log")
logger_fmt = (
"GitFS on {mount_point} [%(process)d]: %(threadName)s: "
"%(message)s".format(mount_point=args.mount_point)
)
handler.setFormatter(Formatter(fmt=logger_fmt))
if args.sentry_dsn != "":
from raven.conf import setup_logging
from raven.handlers.logging import SentryHandler
sentry_handler = SentryHandler(
args.sentry_dsn,
tags={
"owner": args.user,
"remote": args.remote_url,
"mountpoint": args.mount_point,
},
)
sentry_handler.setLevel("ERROR")
setup_logging(sentry_handler)
log.addHandler(sentry_handler)
handler.setLevel(args.log_level.upper())
log.setLevel(args.log_level.upper())
log.addHandler(handler)
# set cache size
lru_cache.maxsize = args.cache_size
# return absolute repository's path
args.repo_path = os.path.abspath(args.repo_path)
return args