承接 understand/understand-laravel5 相关项目开发

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

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

understand/understand-laravel5

Composer 安装命令:

composer require understand/understand-laravel5

包简介

Laravel 5, 6, 7, 8, 9, 10, 11 and 12 service provider for Understand.io

README 文档

README

Latest Version on Packagist Quality Score Total Downloads

Introduction

This packages provides a full abstraction for Understand.io and provides extra features to improve Laravel's default logging capabilities. It is essentially a wrapper around Laravel's event handler to take full advantage of Understand.io's data aggregation and analysis capabilities.

Quick start

  1. Add the package to your project
composer require understand/understand-laravel
  1. Add the ServiceProvider to the providers array in config/app.php
Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider::class,
  1. Set your Understand.io input token in your .env file
UNDERSTAND_ENABLED=true
UNDERSTAND_TOKEN=your-input-token-from-understand-io
  1. Send your first error
// anywhere inside your Laravel app
\Log::error('Understand.io test error');

How to send events/logs

Laravel logs

By default, Laravel automatically stores its logs in storage/logs. By using this package, your log data will also be sent to your Understand.io channel. This includes error and exception logs, as well as any log events that you have defined (for example, Log::info('my custom log')).

\Log::info('my message', ['my_custom_field' => 'my data']);

PHP/Laravel exceptions

By default, all errors and exceptions with code fragments and stack traces will be sent to Understand.io.

The following extra information will be collected:

Type Default Config Key Config Options
SQL queries Enabled UNDERSTAND_SQL= true or false
SQL query values/bindings Disabled UNDERSTAND_SQL_BINDINGS= true or false
HTTP request query string data Enabled UNDERSTAND_QUERY_STRING= true or false
HTTP request form or JSON data Enabled UNDERSTAND_POST_DATA= true or false

Additionally, you can specify which HTTP request field values should not be sent to Understand.io. By default, the following field values will be hidden:

UNDERSTAND_HIDDEN_REQUEST_FIELDS=password,password_confirmation,access_token,secret_key,token,access_key

If you wish you can publish the configuration file and make desired adjustments. See Advanced configuration

How to send data asynchronously

Async handler

By default each log event will be sent to Understand.io's api server directly after the event happens. If you generate a large number of logs, this could slow your app down and, in these scenarios, we recommend that you make use of an async handler. To do this, set the config parameter UNDERSTAND_HANDLER to async in your .env file.

# Specify which handler to use - sync, queue or async. 
# 
# Note that the async handler will only work in systems where 
# the CURL command line tool is installed
UNDERSTAND_HANDLER=async

The async handler is supported in most systems - the only requirement is that the CURL command line tool is installed and functioning correctly. To check whether CURL is available on your system, execute following command in your console:

curl -h

If you see instructions on how to use CURL then your system has the CURL binary installed and you can use the async handler.

Keep in mind that Laravel allows you to specify different configuration values in different environments. You could, for example, use the async handler in production and the sync handler in development.

How to report Laravel 5.0 (>= 5.0, < 5.1) exceptions

Laravel's (>= 5.0, < 5.1) exception logger doesn't use event dispatcher (laravel/framework#10922) and that's why you need to add the following line to your Handler.php file (otherwise Laravel's exceptions will not be sent Understand.io).

  • Open app/Exceptions/Handler.php and put this line \UnderstandExceptionLogger::log($e) inside report method.

    public function report(Exception $e)
    {
        \UnderstandExceptionLogger::log($e);
    
        return parent::report($e);
    }

Advanced Configuration

  1. Publish configuration file
php artisan vendor:publish --provider="Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider"

Log Filter

To filter out specific log types a custom log filter can be provided.

Example filter class

// app/Logging/UnderstandLogFilter.php
<?php

declare(strict_types=1);

namespace App\Logging;

use Illuminate\Support\Str;

class UnderstandLogFilter
{
    public function __invoke($level, $message, $context): bool
    {
        if ($level === 'warning' && Str::contains(strtolower($message), 'deprecated')) {
            return true;
        }

        return false;
    }
}

and then it can be configured in understand-laravel.php

<?php
// ...
// config/understand-laravel.php
'log_filter' => \App\Logging\UnderstandLogFilter::class,

The log_filter config value must be a callable type:

The suggested way would be to create an invokable class since it's hard to serialise anonymous functions (Laravel config cache):

The log filter interface must be as follows: $callable($level, $message, $context). The result of the filter must be a boolean value:

  • TRUE, the log should be ignored and NOT delivered to Understand.io
  • FALSE, the log should be delivered to Understand.io

The ignored_logs config value has higher precedence than log_filter.

Requirements

UTF-8

This package uses the json_encode function, which only supports UTF-8 data, and you should therefore ensure that all of your data is correctly encoded. In the event that your log data contains non UTF-8 strings, then the json_encode function will not be able to serialize the data.

http://php.net/manual/en/function.json-encode.php

License

The Laravel Understand.io service provider is open-sourced software licensed under the MIT license

understand/understand-laravel5 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 2
  • Forks: 15
  • 开发语言: PHP

其他信息

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