承接 forci/catchable-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

forci/catchable-bundle

Composer 安装命令:

composer require forci/catchable-bundle

包简介

A bundle to collect your unhandled exceptions

README 文档

README

Register the bundle as usual and mount its routing.

For this bundle to make any sense at all, you need to create a separate connection and a separate entity manager. From version 0.7 and up, you no longer need any config for this bundle. Follow https://symfony.com/doc/4.4/doctrine/multiple_entity_managers.html and map ForciCatchableBundle to your separate EM.

Better yet, create a completely separate database. Having a separate entity manager will also mean you will NOT be able to migrate this with DoctrineMigrationsBundle as it does NOT support multiple entity managers (at least to my knowledge). So create/update your separate database as per your project's deployment strategy and/or needs.

The above configuration uses the default one and WILL NOT WORK in case you have an exception thrown by Doctrine, as it will also close the entity manager which is responsible for writing it to the database.

WARNING: This bundle is NOT meant to be a replacement for your file or else logging. It is meant to work alongside your existing infrastructure and make viewing errors easier and nicer via your admin interface.

Versions >= ~0.6

In your config_prod.yml

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: critical
            handler:      grouped
            # 404 and 405 can build up tons if unnecessary data
            # You may be better off tracking those from your web server's logs
            excluded_http_codes: [404, 405]
            # Alternatively, exclude just 404s at given paths
#            excluded_404s:
#                # regex: exclude all 404 errors from the logs
#                - ^/
        grouped:
            type:    group
            members: [streamed, buffered, catchable]
        # Log errors to a file
        streamed:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            include_stacktraces: true
        # Buffer errors to be sent via swift mailer
        buffered:
            type:    buffer
            handler: swift
        # Actual swift mailer handler that gets invoked when action_level: critical
        # from the main handler occurs
        swift:
            type:       swift_mailer
            from_email: errors@some-domain.com
            to_email:   "dev1@some-domain.com"
            # or list of recipients
            # to_email:   [dev1@some-domain.com, dev2@some-domain.com, ...]
            subject:    "[My Project] An Error in PROD Occurred!"
            level:      debug
            include_stacktraces: true
        # CatchableBundle's buffer handler. Logs are formatted using the hardcoded \Monolog\Formatter\ScalarFormatter
        # and stored locally in an array. After that, upon an Exception, the `Forci\Bundle\Catchable\Subscriber\ExceptionSubscriber`
        # is invoked, and fetches the logs from this buffer handler. This allows you to have your Symfony logs persisted
        # together with the serialized \Throwable instance.
        catchable:
            type: service
            id: forci.catchable.monolog.handler.log_buffer

You could also pass Catchable's logs through a FilterHandler to get rid of bloat such as deprecations. This allows you to only have critical error information persisted, but deprecations logged to a file by the remaining handlers. Either use accepted_levels or min_level / max_level, whichever suits your needs best. Just be careful if allowing deprecations to be persisted. Upon many 404 errors, you'll get the database fill up quickly with redundant data. In the future, functionality like ignored errors (such as the aforementioned HttpNotFoundException) will be added.

        catchable:
            type: filter
            handler: catchable_real
            # Either
#            min_level: debug
#            max_level: emergency
            # Or
            accepted_levels: [debug, critical]
        catchable_real:
            type: service
            id: forci.catchable.monolog.handler.log_buffer

Alternatively, instead of fingers_crossed, you could use a filter or buffer or any other handler. Please note: When using buffer, it must flush at some point. This must also happen BEFORE the ExceptionSubscriber is fired. As it is, using it alongside your fingers_crossed file and/or email logging is the best approach. Other handlers haven't been tested with Catchable's buffer service. Use at your own risk.

monolog:
    handlers:
        # Filter logs to a level you'd like
        filter:
            type: filter
            level: debug
            handler: catchable
        # Then channel them into Catchable's buffer for use by the ExceptionSubscriber as described above
        catchable:
            type: service
            id: forci.catchable.monolog.handler.log_buffer

Versions <= ~0.5

In your config.yml

forci_catchable:
    entity_manager: default

Where entity_manager is your SEPARATE entity manager.

In your config_prod.yml

monolog:
    handlers:
        limitless:
            type: service
            id: forci.catchable.handler.limitless_buffer

This handler will collect all the logs and store them in an array, which will be available for Catchable's subscriber and saved to the database Exception entry.

This also makes it possible for you to use the logger and log critical data that may be important in case of a disaster.

Then, make a link somewhere in your app to

<a href="{{ path('forci_catchable_root') }}">
    Errors
</a>

Enjoy!

Release 0.6

  • Improved buffer handler. You can now configure it in your main chain of handlers.
  • Removed deprecations. Allows Symfony 5 compatibility.
  • Now uses FlattenException from Symfony's ErrorHandler component, rather than Debug.
  • Removed hack around serializing \Throwable via the deprecated FatalThrowableError class.

Upgrade 0.5 -> 0.6

  • Symfony requirements are now ~4.4|~5.0
  • The Forci\Bundle\Catchable\Serializer\ExceptionSerializer service is removed. All of its code are now in Forci\Bundle\Catchable\Collector\ThrowableCollector
  • The forci.catchable.handler.limitless_buffer service has been removed in favor of a simpler forci.catchable.monolog.handler.log_buffer
  • Your buffering and/or filtering logic must now be handled by any of the built-in Monolog handlers. This makes buffering relevant logs more streamlined and in line with your other handlers.

--

TODOs

  • Make it possible to ignore an exception class
  • Add a "Hide User Deprecated" checkbox that hides log messages starting with "User Deprecated"
  • Add file and message hashes, search by hash instead for better performance as these are text and have no indexes (Blame Doctrine for not allowing to specify index length)
  • Rename to ExceptionBundle, ExceptionCollector, ExceptionSerializer, etc
  • Add filter exceptions config
  • Hash Error type, file, line, message, current DATE/HOUR and increment an "occurrences" counter @ Catchable Entity

forci/catchable-bundle 适用场景与选型建议

forci/catchable-bundle 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 10.36k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wucdbm」 「forci」 「exception bundle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 forci/catchable-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 forci/catchable-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 forci/catchable-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-03