本文整理汇总了Python中sentry_sdk.integrations.logging.LoggingIntegration方法的典型用法代码示例。如果您正苦于以下问题:Python logging.LoggingIntegration方法的具体用法?Python logging.LoggingIntegration怎么用?Python logging.LoggingIntegration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry_sdk.integrations.logging
的用法示例。
在下文中一共展示了logging.LoggingIntegration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logging
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging(sentry_init, capture_events):
sentry_init(
integrations=[FalconIntegration(), LoggingIntegration(event_level="ERROR")]
)
logger = logging.getLogger()
app = falcon.API()
class Resource:
def on_get(self, req, resp):
logger.error("hi")
resp.media = "ok"
app.add_route("/", Resource())
events = capture_events()
client = falcon.testing.TestClient(app)
client.simulate_get("/")
(event,) = events
assert event["level"] == "error"
示例2: test_logging
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging(sentry_init, capture_events, app):
# ensure that Flask's logger magic doesn't break ours
sentry_init(
integrations=[
flask_sentry.FlaskIntegration(),
LoggingIntegration(event_level="ERROR"),
]
)
@app.route("/")
def index():
app.logger.error("hi")
return "ok"
events = capture_events()
client = app.test_client()
client.get("/")
(event,) = events
assert event["level"] == "error"
示例3: test_logging_filters
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging_filters(sentry_init, capture_events):
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()
should_log = False
class MyFilter(logging.Filter):
def filter(self, record):
return should_log
logger.addFilter(MyFilter())
logger.error("hi")
assert not events
should_log = True
logger.error("hi")
(event,) = events
assert event["logentry"]["message"] == "hi"
示例4: test_logging
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging(sentry_init, capture_events, app, get_client):
# ensure that Bottle's logger magic doesn't break ours
sentry_init(
integrations=[
bottle_sentry.BottleIntegration(),
LoggingIntegration(event_level="ERROR"),
]
)
@app.route("/")
def index():
app.logger.error("hi")
return "ok"
events = capture_events()
client = get_client()
client.get("/")
(event,) = events
assert event["level"] == "error"
示例5: init_sentry
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def init_sentry():
distribution = get_distribution("MozPhab")
sentry_logging = LoggingIntegration(
level=logging.INFO,
event_level=None,
# The default event_level is logging.ERROR, which will report any
# "logging.error(...)" call to Sentry. However, we respond to
# incorrect usage with "logging.error(...)" messages, which we don't
# want to report to Sentry.
)
sentry_sdk.init(
dsn="https://e8a2a97b86c7472f9308186547aebfa2@sentry.prod.mozaws.net/502",
integrations=[sentry_logging],
release=distribution.version,
)
示例6: test_integration_scoping
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_integration_scoping(sentry_init, capture_events):
logger = logging.getLogger("test_basics")
# This client uses the logging integration
logging_integration = LoggingIntegration(event_level=logging.WARNING)
sentry_init(default_integrations=False, integrations=[logging_integration])
events = capture_events()
logger.warning("This is a warning")
assert len(events) == 1
# This client does not
sentry_init(default_integrations=False)
events = capture_events()
logger.warning("This is not a warning")
assert not events
示例7: test_logging_works_with_many_loggers
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging_works_with_many_loggers(sentry_init, capture_events, logger):
sentry_init(integrations=[LoggingIntegration(event_level="ERROR")])
events = capture_events()
logger.info("bread")
logger.critical("LOL")
(event,) = events
assert event["level"] == "fatal"
assert not event["logentry"]["params"]
assert event["logentry"]["message"] == "LOL"
assert any(crumb["message"] == "bread" for crumb in event["breadcrumbs"])
示例8: test_logging_extra_data
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging_extra_data(sentry_init, capture_events):
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()
logger.info("bread", extra=dict(foo=42))
logger.critical("lol", extra=dict(bar=69))
(event,) = events
assert event["level"] == "fatal"
assert event["extra"] == {"bar": 69}
assert any(
crumb["message"] == "bread" and crumb["data"] == {"foo": 42}
for crumb in event["breadcrumbs"]
)
示例9: test_logging_stack
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging_stack(sentry_init, capture_events):
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()
logger.error("first", exc_info=True)
logger.error("second")
event_with, event_without, = events
assert event_with["level"] == "error"
assert event_with["threads"]["values"][0]["stacktrace"]["frames"]
assert event_without["level"] == "error"
assert "threads" not in event_without
示例10: test_logging_level
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_logging_level(sentry_init, capture_events):
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()
logger.setLevel(logging.WARNING)
logger.error("hi")
(event,) = events
assert event["level"] == "error"
assert event["logentry"]["message"] == "hi"
del events[:]
logger.setLevel(logging.ERROR)
logger.warning("hi")
assert not events
示例11: test_transport_infinite_loop
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def test_transport_infinite_loop(httpserver, request):
httpserver.serve_content("ok", 200)
client = Client(
"http://foobar@{}/123".format(httpserver.url[len("http://") :]),
debug=True,
# Make sure we cannot create events from our own logging
integrations=[LoggingIntegration(event_level=logging.DEBUG)],
)
with Hub(client):
capture_message("hi")
client.flush()
assert len(httpserver.requests) == 1
示例12: setup_logging
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def setup_logging():
sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture info and above as breadcrumbs
event_level=logging.WARNING, # Send errors as events
)
sentry_sdk.init(
settings.SENTRY_URL,
integrations=[sentry_logging],
environment=settings.SENTRY_ENVIRONMENT,
)
示例13: configure_sentry_logging
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def configure_sentry_logging(sentry_url):
sentry_logging = LoggingIntegration(
level=logging.WARNING, # Capture warning and above as breadcrumbs
event_level=logging.ERROR, # Send errors as events
)
sentry_sdk.init(dsn=sentry_url, integrations=[sentry_logging], release=__version__)
示例14: setup_log
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def setup_log(sentry_url, print_errors):
global logger, production
sentry_logging = LoggingIntegration(
level=logging.INFO,
event_level=logging.INFO
)
sentry_sdk.init(dsn=sentry_url, integrations=[sentry_logging])
logger = logging.getLogger(__name__)
p_errors = print_errors
production = True
示例15: setup_sentry
# 需要导入模块: from sentry_sdk.integrations import logging [as 别名]
# 或者: from sentry_sdk.integrations.logging import LoggingIntegration [as 别名]
def setup_sentry(enable_flask_integration: bool = False) -> None:
sentry_dsn = os.environ.get("SENTRY_DSN")
environment = os.environ.get("DEPLOY_ENV")
if sentry_dsn is not None:
log.info("Initializing sentry", dsn=sentry_dsn)
integrations: List[Any] = [LoggingIntegration(level=logging.INFO, event_level=None)]
if enable_flask_integration:
integrations.append(FlaskIntegration())
sentry_sdk.init(
dsn=sentry_dsn,
integrations=integrations,
release=pkg_resources.get_distribution("raiden-services").version,
environment=environment,
)