nagi/laravel-newrelic-log-api

这是我的包 laravel-newrelic-log-api

v1.0.5 2024-09-09 15:58 UTC

This package is auto-updated.

Last update: 2024-09-09 15:58:41 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

将 New Relic Log API 集成到您的 Laravel 应用程序中。它主要利用队列在后台将日志发送到 New Relic API。请确保您已配置队列工作进程。

    // in loggin.php
    'stack' => [
                'driver' => 'stack',
                'channels' => ['single', 'newrelic-log-api'],
                'ignore_exceptions' => false,
            ],

        //...
        'newrelic-log-api' => [
            'driver' => 'monolog',
            'handler' => \Nagi\LaravelNewrelicLogApi\LaravelNewrelicLogApi::logHandler(),
            'level' => 'debug',
        ],
logger('newrelic-log-api')->info('Hey Mom!');

// or if you are using stack

logger()->info('Hey Mom!');

支持我

您的业务是否依赖我的贡献?请与我联系,在 PayPal 上支持我。所有承诺将专门用于分配维护和新奇功能的人力。

安装

您可以通过 composer 安装此包

composer require nagi/laravel-newrelic-log-api

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-newrelic-log-api-config"

这是发布配置文件的内容

return [
    'enabled' => env('NEWRELIC_ENABLED', false),

    /**
     * New Relic API key or License key
     *
     * @see https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/#setup
     */
    'api_key' => env('NEWRELIC_API_KEY'),

    /**
     * The base URL for the new relic log API
     *
     * @see https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/#endpoint
     */
    'base_url' => env('NEWRELIC_BASE_URL', 'https://log-api.eu.newrelic.com'),

    /**
     * The minimum logging level at which this handler will be triggered
     */
    'level' => env('NEWRELIC_LEVEL', 'debug'),

    /**
     * Retry sending the log to New Relic API
     */
    'retry' => env('NEWRELIC_RETRY', 3),

    /**
     * Delay between retries in milliseconds
     */
    'retry_delay' => env('NEWRELIC_RETRY_DELAY', 1000),

    /**
     * Queue name to use for sending logs to New Relic API
     */
    'queue' => env('NEWRELIC_QUEUE', env('QUEUE_CONNECTION')),

    /**
     * Log handler to use for sending logs to New Relic API
     */
    'log_handler' => \Nagi\LaravelNewrelicLogApi\NewrelicLogHandler::class,
];

🚨 确保您已配置队列工作进程。

用法

获取您的 New Relic 许可/API 密钥

https://one.newrelic.com/api-keys

在您的 .env 中添加环境值

NEWRELIC_ENABLED=true
NEWRELIC_API_KEY=<your_key>

# if your account is not EU change the baseurl
# https://log-api.newrelic.com/log/v1
NEWRELIC_BASE_URL=https://log-api.eu.newrelic.com

在您的配置中添加 New Relic 通道

在您的 logging.php 中添加 new-relic-log-api 通道

        'newrelic-log-api' => [
            'driver' => 'monolog',
            'handler' => \Nagi\LaravelNewrelicLogApi\LaravelNewrelicLogApi::logHandler(),
            'level' => env('NEWRELIC_LEVEL', 'debug')
        ],

将其添加到您的日志堆栈中

logging.php

    'stack' => [
                'driver' => 'stack',
                'channels' => ['single', 'newrelic-log-api'],
                'ignore_exceptions' => false,
            ],

监听事件

如果您对获取 New Relic API 的响应感兴趣,您可以监听事件 NewrelicLogApiResponseEvent。它将包含状态和 API 的响应。

    protected $listen = [
        NewrelicLogApiResponseEvent::class => [
            NewrelicLogApiResponseListener::class,
        ],
    ];

关于上下文日志(属性)的说明

当在上下文中发送以下属性之一时,它将被前缀 attr_,以避免覆盖整个消息。

参见: New Relic Log API

扩展

此包中的所有类都是通过 Laravel 的服务容器加载的,这意味着您可以轻松地用您自己的实现替换它们。自行承担风险。

测试

composer test

更改日志

请参阅 CHANGELOG 以获取有关最近更改的更多信息。

贡献

请参阅 CONTRIBUTING 以获取详细信息。

安全漏洞

请参阅 我们的安全策略 了解如何报告安全漏洞。

致谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅 许可文件