定制 exbico/monolog-exception-processor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

exbico/monolog-exception-processor

最新稳定版本:2.0.0

Composer 安装命令:

composer require exbico/monolog-exception-processor

包简介

Monolog processor of exceptions and exception with context

README 文档

README

Latest Stable Version Total Downloads License

INSTALLATION

The preferred way to install this extension is through composer.

Either run

composer require exbico/monolog-exception-processor

or add

"exbico/monolog-exception-processor": "*"

to the require section of your application's composer.json file.

Basic Usage

<?php

use Exbico\Formatter\ExceptionProcessor;
use Monolog\Logger;

$logger = new Logger();
$logger->pushProcessor(new ExceptionProcessor);

USAGE

<?php
try{
    throw new Exception('test');
}catch(Throwable $exception) {
    $logger->alert('message', [..., 'exception' => $exception, ...]);
}

Resulted record for any Throwable

[
  "message" => "message",
  "context" => [...],
  ...
  "extra" => [
    ...
    "exception" => [
      "message" => "test",
      "class"   => "Exception",
      "trace"   => "#0 {main}",
    ],
    ...
  ],
]

Resulted record, if Throwable has previous

[
  "message" => "message",
  "context" => [...],
  ...
  "extra"   => [
    ...
    "exception" => [
      "message"  => "test",
      "class"    => "Exception",
      "trace"    =>"#0 {main}",
      "previous" => [
        "message" => "previous message",
        "class"   => "Class of previous",
        "trace"   => "#0 {main}",
      ],
    ],
    ...
  ],
]

You can implement ExceptionWithContext or extend ContextException

<?php

use Exbico\Formatter\ExceptionWithContext;
use Exbico\Formatter\ExceptionWithContextInterface;

class FooException extends ExceptionWithContext
{

}

class BarException implements ExceptionWithContextInterface
{
    ...

    /**
     * @return array<string, mixed>
     */
    public function getContext(): array
    {
        ...
    }
}

try {
    throw new FooException(message: 'test', context: ['id' => 12, 'text' => '...'], previous: $previousException);
} catch (FooException $exception) {
    $logger->alert('message', ['id' => 34, 'exception' => $exception, 'date' => '...']);
}

Then record will look:

[
  "message" => "message",
  "context" => [
    "id"   => 34,
    "date" => "...",
    "text" => "...",
  ],
  ...
  "extra" => [
    ...
    "exception" => [
      "message"  => "test",
      "class"    => "Exception",
      "trace"    =>"#0 {main}",
      "previous" => [
        "message" => "previous message",
        "class"   => "Class of previous",
        "trace"   => "#0 {main}",
        "context" => [
          ...
        ],
      ],
      "context" => [
        "id"   => 34,
        "date" => "...",
      ],
    ],
    ...
  ],
]

WARNING if you have equal keys in both contexts, then value of exception context has higher priority

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固