dziki/monolog-sentry-bundle

该软件包已被废弃,不再维护。没有建议的替代软件包。

通过用户、用户代理、修订和Symfony版本数据改进Sentry日志记录

安装次数: 78,315

依赖关系: 0

建议者: 0

安全: 0

星标: 31

关注者: 4

分支: 7

开放问题: 0

类型:symfony-bundle

v1.1.0 2020-05-31 22:12 UTC

This package is auto-updated.

Last update: 2023-03-01 00:29:53 UTC


README

Latest Stable Version Build Status Coverage Status Scrutinizer Code Quality SensioLabsInsight License FOSSA Status

为Monolog日志记录添加有用数据的Bundle,例如用户名、解析的用户代理头部、主机名、Symfony版本、提交哈希等 - 您可以为所有日志提供自定义标签。

安装

使用composer require dziki/monolog-sentry-bundle命令安装Bundle。

TL;DR

默认的monolog raven handler与开启和关闭Bundle的sentry/sentry包客户端对相同错误处理的比较,配置了一些基本配置。如您所见,在开启Bundle后,浏览器、用户、面包屑和有用的标签显示出来,使错误日志更容易阅读。

之前

before

之后

after

启用Bundle

config/bundles.php中添加条目

return [
    // ...
    Dziki\MonologSentryBundle\MonologSentryBundle::class => ['all' => true],
];

或到app/AppKernel.php

<?php // app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Dziki\MonologSentryBundle\MonologSentryBundle(),
        );
        // ...
    }
    // ...
}

配置

默认配置不做任何事情,您需要根据需要手动调整

monolog_sentry:
    user_context: false # append username from TokenStorage to log
    user_agent_parser: false # install donatj/phpuseragentparser package
                             # and set to 'phpuseragent' to parse browser name, version and platform from user agent

您可以通过将值设置为true来开启日志用户上下文 - 这需要symfony/security-bundle包。需要user_agent_parser作为值的有效用户代理头部解析服务。解析用户代理每请求花费约0.1毫秒(使用原生解析器可达1毫秒),因此...

缓存已解析的用户代理

在提供实现Psr\SimpleCache\CacheInterface服务的cache配置条目下支持缓存。从Symfony 4.1版本开始,有默认的简单缓存服务cache.app.simple,在之前的版本中,您需要定义自己的服务

monolog_sentry:
    cache: cache.app.simple # service implementing "Psr\SimpleCache\CacheInterface" interface

自定义标签

您可以通过添加自定义标签来扩展日志数据的数量。例如,为了记录Symfony版本、有用的Sentry环境和服务器名称,您应该将配置修改为以下内容

monolog_sentry:
    ...
    tags:
        symfony_version: !php/const Symfony\Component\HttpKernel\Kernel::VERSION # useful for regression check
        commit: '%env(APP_REVISION)%' # for example hash of commit, set your own environment variable or parameter
        environment: '%env(SERVER_NAME)%' # Sentry environment discriminator, much more useful than default `prod`

完整的基本配置

monolog_sentry:
    user_context: true # append username from TokenStorage to log
    user_agent_parser: phpuseragent # parse browser name, version and platform from user agent
    cache: cache.app.simple # service implementing "Psr\SimpleCache\CacheInterface" interface, since SF 4.1
    tags:
        symfony_version: !php/const Symfony\Component\HttpKernel\Kernel::VERSION # useful for regression check
        commit: '%env(APP_REVISION)%' # for example hash of commit, set your own environment variable or parameter
        environment: '%env(SERVER_NAME)%' # Sentry environment discriminator, much more useful than default `prod`

用户代理解析器

Bundle支持两种解析器

可以通过user_agent_parser值进行配置,分别是phpuseragentnative。您还可以添加自己的,通过提供实现ParserInterface的服务名称。

提示

  • stop_buffering: false添加到您的fingers_crossed处理程序中,以将低级消息通知作为面包屑
monolog:
    handlers:
        main:
            type:           fingers_crossed
            action_level:   error
            handler:        buffered
            stop_buffering: false
        sentry:
            type:    raven
            dsn:     '%env(SENTRY_DSN)%'
            level:   info # logs which will be shown as breadcrumbs in Sentry issue
            release: 1.0.0
  • 将Sentry处理程序的release选项添加到monolog配置中,以便于回归寻找
monolog:
    handlers:
        ...
        sentry:
            ...
            release: '%env(APP_VERSION)%' # version tag or any release ID

许可证

MonologSentryBundle在MIT许可证下发布。

FOSSA Status