承接 passchn/cakephp-logging 相关项目开发

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

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

passchn/cakephp-logging

最新稳定版本:0.1.0

Composer 安装命令:

composer require passchn/cakephp-logging

包简介

Logging plugin for CakePHP

README 文档

README

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require passchn/cakephp-logging

Load the plugin:

bin/cake plugin load Passchn/CakeLogging

Usage

The plugin enables you to configure the Cake Log class to use implementations of the PSR-3 logger interface which are available in your Applications container.

It comes with a MultiLogger where you can define multiple implementations as fallbacks.

Configuration

In your config/app.php you can configure the logger like this:

return [
    'Log' => [
        'debug' => [
            'className' => LoggerFacade::class, // use the facade to configure the actual logger
            LoggerFacade::CONFIG_KEY_UNDERLYING_LOGGER => MyLoggerImplementation::class, // a LoggerInterface implementation
        ],
    ],
];

Note that MyLoggerImplementation must be available in your container.

MultiLogger usage

You can also use the MultiLogger to define multiple fallbacks:

return [
    
    // default config for the multi logger
    MultiLoggerConfig::class => [
        MultiLoggerConfig::CONFIG_KEY_LOGGERS => [
            SentryLogger::class,
            FileLog::class,
        ],
    ],
    
    'Log' => [
        'debug' => [
            'className' => LoggerFacade::class,
            LoggerFacade::CONFIG_KEY_UNDERLYING_LOGGER => MultiLogger::class,
            MultiLoggerConfig::class => [
                // multi logger config can be overridden here
                MultiLoggerConfig::CONFIG_KEY_LOGGERS => [
                    MyLoggerImplementation::class,
                    AnotherLoggerImplementation::class,
                    FileLog::class, // the default file logger as fallback
                ],
            ],
            'path' => LOGS,
            'file' => 'debug',
            'url' => env('LOG_DEBUG_URL', null),
            'scopes' => null,
            'levels' => ['notice', 'info', 'debug'],
        ],
        
        'error' => [
            // ...
        ],
        
        'emergency' => [
            'className' => FileLog::class,
            'className' => LoggerFacade::class,
            LoggerFacade::CONFIG_KEY_UNDERLYING_LOGGER => MultiLogger::class,
            MultiLoggerConfig::CONFIG_KEY_LOGGERS => [
                SmsEmergencyLogger::class,
                AlexaTextToSpeechAlarmWithWaterSprinklerLogger::class,
            ],
        ],
    ],
];

If you use the default FileLogger, leave the config keys as they are as they will be used for the FileLog configuration.

Every logger used by the multi logger must be an implementation of the LoggerInterface which is available in your container.

Configuring custom loggers

If you want to configure a custom logger, you can do so by implementing the LoggerInterface and adding it to your container.

use Psr\Log\LoggerInterface;

class MyLoggerImplementation extends \Psr\Log\AbstractLogger implements LoggerInterface
{
    public function __construct(
        private readonly SomeDependency $dependency,
    ) {
        // ...
    }

    public function log($level, $message, array $context = [])
    {
        // your implementation
    }
}

Then, you can add it to your container.

In your Application.php:

public function services(ContainerInterface $container): void
{
    $container->add(
        MyLoggerImplementation::class, 
        fn () => new MyLoggerImplementation(
            $container->get(SomeDependency::class),
        ),
    );
}

Then, you can just use the implementation by adding the class name in your app.php configuration for the respective logging scope:

MultiLoggerConfig::CONFIG_KEY_LOGGERS => [
    MyLoggerImplementation::class,
    ...
],

Learn more about Dependency Injection in the CakePHP Book.

Collaboration

If you have any ideas or encounter a bug, feel free to open an issue or a pull request.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固