承接 minvws/laravel-logging 相关项目开发

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

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

minvws/laravel-logging

最新稳定版本:v3.3.0

Composer 安装命令:

composer require minvws/laravel-logging

包简介

Laravel provider for logging functionality

README 文档

README

This package extends the minvws/audit-logger package and provides a generic logging service for Laravel applications for the RDO platform. It allows to easily log events to the database, syslog or other destinations.

Installation

Composer

You can install the package via the composer package manager:

composer require minvws/laravel-logging

Configuration

The package can be configured in the logging.php file. The following options are available:

Option Description
dblog_enabled Enable logging to the database
syslog_enabled Enable logging to syslog
rabbitmq_enabled Enable logging to RabbitMQ
auditlog_model The model to use for logging to the database
log_full_request Log the full HTTP request
syslog_encrypt Encrypt the data before sending to syslog
syslog_pubkey The public key to use for encryption
syslog_secret The private key to use for encryption
rabbitmq_additional_allowed_events Additional events that can be logged to RabbitMQ
rabbitmq_log_pii Log PII data to RabbitMQ

There are currently three logging destinations available: the database, syslog and rabbitmq.

Database logging

The basic AuditLog model is available and by default configured. If a different model is preferred to use, the auditlog_model option can be set to the actual class to use.

The default model can be created in pgsql with the following statement:

CREATE TABLE public.audit_logs
(
    email              character varying(320),
    request            json,
    pii_request        text,
    created_at         timestamp(0) without time zone,
    event_code         character varying(255),
    action_code        character varying(255),
    source             character varying(255),
    allowed_admin_view boolean,
    failed             boolean,
    failed_reason      text
);

When logging to the database To log to the database, there needs to be a (eloquent) model like the AuditLog model. Note that this model is just an example, you can use your own model that might encrypt the actual data for instance.

To "connect" your model to the logging service, you need to set the auditlog_model option to the actual class to use.

See minvws/audit-logger for more information.

Usage:

To use the logger, inject or resolve the LogService class. This class has a single method:

  use MinVWS\Logging\Laravel\LogService;
  
  $logger = app(LogService::class);
  $logger->log((new UserLoginLogEvent())
      ->asExecute()
      ->withActor($user)
      ->withData(['foo' => 'bar'])
      ->withPiiData(['bar' => 'baz'])
      ->withFailed(true, 'invalid login')
  );

Creating custom events

Creating a custom event is easy. You can create a new class that extends the MinVWS\AuditLogger\Events\Logging\GeneralLogEvent class.

  use MinVWS\AuditLogger\Events\Logging\GeneralLogEvent;
  
  class MyCustomEvent extends GeneralLogEvent
  {
      public const EVENT_CODE = '991414';
      public const EVENT_KEY = 'my_custom_event';
  }

Contributing

If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository of this package.

License

This package is open-source and released under the European Union Public License version 1.2. You are free to use, modify, and distribute the package in accordance with the terms of the license.

Part of iCore

This package is part of the iCore project.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: EUPL-1.2
  • 更新时间: 2025-06-12