nix-logger/nix-logger-laravel

v1.3 2024-03-27 08:20 UTC

This package is not auto-updated.

Last update: 2024-09-27 05:53:15 UTC


README

安装

安装 nix-logger/nix-logger-laravel

composer require nix-logger/nix-logger-laravel

config/app.php 文件的 providers 数组中添加服务提供者,在 AppServiceProvider::class 之前

NixLogger\Laravel\NixLoggerServiceProvider::class,

config/app.php 文件的 aliases 数组中添加 Facade

'NixLogger' => NixLogger\Laravel\Facades\NixLogger::class,

配置

通过编辑 .env 文件来配置 Nix-Logger

# .env
NIX_LOGGER_API_KEY=
APP_ENV=
NIX_LOGGER_LEVEL=critical,error,warning

如果您想进一步配置 Nix-Logger,创建并编辑一个 config/nix-logger.php 文件

设置日志报告

config/logging.php 中,通过在 channels 键下添加以下内容来添加 nix-logger 日志通道

'stack' => [
    'driver' => 'stack',
    'channels' => ['single', 'nix-logger'],
    'ignore_exceptions' => false,
],

'nix-logger' => [
  'driver' => 'custom',
  'via' => \NixLogger\Laravel\Logger\NixLogger::class,
],

针对 stderr

'channels' => [
    'stderr' => [
        'driver' => 'monolog',
        'level' => env('LOG_LEVEL', 'debug'),
        'handler' => \NixLogger\Laravel\Handlers\NixLoggerStreamHandler::class,
        'formatter' => env('LOG_STDERR_FORMATTER'),
        'with' => [
            'stream' => 'php://stderr',
        ],
        'processors' => [PsrLogMessageProcessor::class],
    ],
]

用法

\NixLogger::debug('Test');