itafroma/snaglogger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

itafroma/snaglogger

Composer 安装命令:

composer require itafroma/snaglogger

包简介

A PSR-3 logger for Bugsnag

README 文档

README

Snaglogger is a PSR-3-compatible logger that sends log messages to Bugsnag.

Installation

Snaglogger can be added to your project via Composer:

{
    "require": {
        "itafroma/snaglogger": "^2.0"
    }
}

Snaglogger uses semantic versioning. In general, you can pin to ^[MAJOR].0 and be confident you will not receive breaking changes during updates.

Usage

Quickstart

Snaglogger comes with a factory that instantiates the logger with sensible defaults:

use Itafroma\Snaglogger\LoggerFactory;

$key    = 'YOUR BUGSNAG API KEY HERE';
$logger = LoggerFactory::create($key);

Once instantiated, the logger will work as any other PSR-3-compatiable logger:

$logger->info('This is an informational message.');
$logger->error('This is an error.');

The PSR-3 context array

Snaglogger will send the contents of the $context array to Bugsnag as metadata.

Additionally, Snaglogger treats two $context keys as special:

  • If the exception key contains an instance of an exception, Snaglogger will record the log message as an exception instead of an error.
  • If the error-type key is set, Snaglogger will use that as the error type. Otherwise, it will use the error severity.

Finally, Snaglogger will use the $context array for placeholder replacement within the log message:

$message = 'The {location} is on fire!';
$context = ['location' => 'roof'];

// Bugsnag will record the error message as "The roof is on fire!"
$logger->error($message, $context);

Severity levels

Bugsnag only supports three severity levels: info, warning, and error. However, PSR-3 requires loggers to support eight: emergency, alert, critical, error, warning, notice, info, and debug. By default, Snaglogger maps these additional log levels to the closest Bugsnag severity level:

  • emergency → error
  • alert → error
  • critical → error
  • error → error
  • warning → warning
  • notice → info
  • info → info
  • debug → info

Advanced usage

Some functionality can be customized by implementing certain interfaces:

More information can be found in those interfaces' inline documentation.

You may also want to customize the Bugsnag client.

To override Snaglogger's default functionality, you will need to:

  1. Implement your own concrete class of \Itafroma\Snaglogger\LoggerFactoryInterface, and/or
  2. Call the Logger constructor directly.

For example:

$client = Client::make('API KEY')->setReleaseStage('prod');
$interpolator = new CustomMessageInterpolator();
$mapper = new CustomSeverityMapper();

$logger = new Logger($client, $interpolator, $mapper);

Contributing

Contributions are welcome! Please see the separate CONTRIBUTING file for more information.

Copyright and license

This extension is copyright Mark Trapp. All Rights Reserved. It is made available under the terms of the MIT license. A copy of the license can be found in the LICENSE file.

Disclaimer

This project has no affliation with Bugsnag in any way. Additional disclaimers can be found in the LICENSE file.

itafroma/snaglogger 适用场景与选型建议

itafroma/snaglogger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.06k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 itafroma/snaglogger 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

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