sec-dojo-com/laravel-ecs-logging

将ECS (Elastic Common Schema) 日志添加到Laravel (更新版)。

dev-main 2023-02-14 16:22 UTC

This package is auto-updated.

Last update: 2024-09-14 19:53:23 UTC


README

此包将ECS (Elastic Common Scheme) 格式添加到您的Laravel应用程序中,允许您将标准日志记录到Elastic。

安装

您可以通过composer安装此包

composer require sec-dojo-com/laravel-ecs-logging

建议您要求jenssegers/agent,这将添加用户代理日志支持。

composer require jenssegers/agent

可选地,您可以使用以下命令发布配置文件:

php artisan vendor:publish --provider="AviationCode\EcsLogging\EcsLoggingServiceProvider" --tag="config"

config/logging.php中注册日志驱动器

return [
    'channels' => [
        // ... Other channels

        'ecs' => [
            'driver' => 'ecs',
            'path' => storage_path('logs/ecs/laravel.json'),
            'level' => 'debug',
            'days' => 14,
        ],
    ]
];

如果您想将此驱动器作为唯一的日志方法,请在.env中定义LOG_CHANNEL=ecs或将ecs通道添加到您的stack driver中。

所有Log::xxx()调用都将记录到JSON文件中。此文件可以被filebeat获取,并将其发送到您的logstash或elasticsearch实例。

配置filebeat

将以下内容添加到您的/etc/filebeat/filebeat.yml文件中

filebeat.inputs:
    - type: log
      enabled: true
      paths:
          - /path-to-your-laravel-app/storage/logs/ecs/*.json
      json:
          message_key: message
          keys_under_root: true
          overwrite_keys: true

错误

ecs-logs包中的当前错误

  • Typed static property Aviation Code\Ecs Logging\Tracing\Correlate::$id must not be accessed before initialization。这是由于在为它们分配值之前尝试访问类型提示的属性,通过用空值初始化它们来修复。

原始存储库

此包是基于AviationCode\EcsLogging的分支。包含更新和错误修复。

分支更改日志

2022年5月13日:添加了通过配置文件禁用日志文件轮换的选项(使用选项disable_rotate

致谢

许可证

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