PHP code example of kriss / webman-logger

1. Go to this page and download the library: Download kriss/webman-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kriss / webman-logger example snippets


use support\facade\Logger;

return array_merge(
    [
        'default' => [
            'handlers' => [
                [
                    'class' => Monolog\Handler\RotatingFileHandler::class,
                    'constructor' => [
                        runtime_path() . '/logs/webman.log',
                        7, //$maxFiles
                        Monolog\Logger::DEBUG,
                    ],
                    'formatter' => [
                        'class' => Monolog\Formatter\LineFormatter::class,
                        'constructor' => [null, 'Y-m-d H:i:s', true],
                    ],
                ]
            ],
        ],
    ],
    Logger::getLogChannelConfigs(), // merge 这个
);



namespace support\facade;

/**
 * @method static void app($msg, string $type = 'info', array $context = [])
 * @method static void sql($msg, string $type = 'info', array $context = [])
 */
class Logger extends \WebmanTech\Logger\Logger
{
}

use support\facade\Logger;

Logger::app('xxx'); // 记录 xxx 到 app channel
Logger::app(['x' => 'y']); // 支持数组写入,写入日志时会转成 json
Logger::app($exception); // 支持 Exception 写入,写入时会记录详细的 trace
Logger::app('xxx', 'error'); // 切换 level
Logger::app('hello: {name}', 'info', ['name' => 'Kriss']); // 使用 PsrLogMessageProcessor 处理,会记录成 "hello Kriss"