mimmi20/monolog-laminas-factory

此包已被废弃,不再维护。没有建议的替代包。

提供一个工厂,用于使用Monolog构建Laminas Logger。

2.0.1 2022-08-02 19:55 UTC

This package is auto-updated.

Last update: 2023-03-01 08:41:55 UTC


README

Monolog Factories for Laminas and Mezzio

此库受以下项目的启发:psr11-monologmonolog-factory.

Latest Stable Version Latest Unstable Version License

代码状态

codecov Average time to resolve an issue Percentage of issues still open

目录

安装

运行

composer require mimmi20/monolog-laminas-factory

与Laminas和Mezzio一起使用

您需要添加配置并注册您想要使用的服务。有多种方法可以实现这一点,但推荐的方法是创建一个新的配置文件 config/autoload/logger.config.php

配置

config/autoload/monolog.global.php

<?php
return [
    'log' => [
        \Laminas\Log\Logger::class => [
            'name' => 'name',
            'exceptionhandler' => false,
            'errorhandler' => false,
            'shutdownhandler' => false,
            'writers' => [], // Writers for Laminas Log
            'processors' => [], // Processors for Laminas Log
            'handlers' => [ // Handlers for Monolog
                // At the bare minimum you must include a default handler config.
                // Otherwise log entries will be sent to the void.
                'default' => [
                    'type' => 'stream',
                    'enabled' => true,
                    'options' => [
                        'stream' => '/var/log/some-log-file.txt',
                    ],
                ],
                
                // Another Handler
                'myOtherHandler' => [
                    'type' => 'stream',
                    'enabled' => false,
                    'options' => [
                        'stream' => '/var/log/someother-log-file.txt',
                    ],
                ],
            ],
            'monolog_processors' => [], // Processors for Monolog
        ],
    ],
];

最小配置

最小配置至少包含一个默认处理器和一个命名服务。请注意,如果您未指定默认处理器,则在连接默认记录器时将使用NullHandler。

最小示例(使用Mezzio作为示例)

<?php

return [
    'log' => [
        \Laminas\Log\Logger::class => [
            'name' => 'name',
            'handlers' => [
                'default' => [
                    'type' => 'stream',
                    'options' => [
                        'stream' => '/var/log/some-log-file.txt',
                    ],
                ],
            ],
        ],
    ],
];

完整配置

完整示例

<?php

return [
    
    'log' => [
        \Laminas\Log\Logger::class => [
            'name' => 'name',
            'handlers' => [
                'default' => [
                    // A Handler type or pre-configured service from the container
                    'type' => 'stream',
                    
                    // Handler specific options.  See handlers below
                    'options' => [
                        'stream' => '/tmp/log_one.txt',
                    
                        // Optional: Formatter for the handler.
                        'formatter' => [
                            'type' => 'line',
                                
                            // formatter specific options.  See formatters below
                            'options' => [], 
                        ], 
                        
                        // Optional: Processor for the handler
                        'processors' => [
                            [
                                // A processor type or pre-configured service from the container
                                'type' => 'psrLogMessage',
                                
                                // processor specific options.  See processors below
                                'options' => [], 
                            ],
                        ],
                    ], 
                ],
            ],
            
            // Processors for Monolog/Logger
            'monolog_processors' => [
                // Array Keys are the names used for the processors
                'processorOne' => [
                    // A processor type or pre-configured service from the container
                    'type' => 'psrLogMessage',
                    
                    // processor specific options.  See processors below
                    'options' => [], 
                ],        
            ],
        ],
    ],
];

许可证

此包使用MIT许可证授权。

请参阅LICENSE.md