定制 pollen-solutions/log 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

pollen-solutions/log

Composer 安装命令:

composer require pollen-solutions/log

包简介

Pollen Solutions - Log Component - Monolog PSR-3 logging implementation.

README 文档

README

Latest Stable Version MIT Licensed PHP Supported Versions

Pollen Solutions Log Component provides a PSR-3 logging implementation based on Monolog.

Installation

composer require pollen-solutions/log

Basic Usage

use Pollen\Log\LogManager;

$log = new LogManager();

// Adds a log record at the DEBUG level
$log->debug('My debug message');

// Adds a log record at the INFO level
$log->debug('My info message');

// Adds a log record at the SUCCESS level
$log->success('My success message');

// Adds a log record at the NOTICE level
$log->notice('My notice message');

// Adds a log record at the WARNING level
$log->warning('My warning message');

// Adds a log record at the ERROR level
$log->error('My error message');

// Adds a log record at the CRITICAL level
$log->critical('My critical message');

// Adds a log record at the ALERT level
$log->alert('My alert message');

// Adds a log record at the EMERGENCY level
$log->emergency('My alert message');
 

Log storage path

By default, if none specific handler is specified, the log manager uses the Monolog RotatingFileHandler. It stores a log file in the app public dir. It is recommended to change it to a more suitable path with appropriate write file permissions.

use Pollen\Log\LogManager;

$log = (new LogManager())->setDefaultStoragePath('/var/log/myapp');

Create a built-in channel and use it

Like the default log channel, the built-in channel uses the RotatingFileHandler and LineFormatter. But you can customizes some of its parameters.

use Pollen\Log\Logger;
use Pollen\Log\LogManager;

$log = new LogManager();

$log->registerChannel('my-channel', [
       /** 
        * Log filename (relative or absolute).
        * @see \Monolog\Handler\RotatingFileHandler
        * @var string|null
        */
        'filename' => null,
       /** 
        * Rotation frequency.
        * @see \Monolog\Handler\RotatingFileHandler
        * @var int|null
        */
       'rotate' => null,
       /** 
        * Minimum logging level.
        * @see \Monolog\Handler\RotatingFileHandler
        * @var string|null
        */
        'level'  => Logger::SUCCESS,
       /** 
        * Line format.
        * @see \Monolog\Formatter\LineFormatter
        * @var string|null
        */
      'format' => null,
       /** 
        * Date format. 
        * @see \Monolog\Formatter\LineFormatter
        * @var string|null
        */
      'date_format' => null
]);

$log->channel('my-channel')->success('Test log success message');

Create your own custom channel

Monolog purposes a large variety of handlers and formatters. You might need to use your own suit and use it in Pollen Solutions Log Component.

use Monolog\Handler\NativeMailerHandler;
use Pollen\Log\Logger;
use Pollen\Log\LogManager;

$log = new LogManager();

$channel = new Logger(
    'mailer',
    [new NativeMailerHandler('to@domain.ltd', 'You have a log report message !', 'from@domain.ltd')]
);

$log->addChannel($channel);

$log->channel('mailer')->error('Test log error message');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固