<?php
require_once 'vendor/autoload.php';
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$dateFormat = "Y-m-d H:i:s";
$output = "[%datetime%] %channel%.%level_name%: %message% %context%\n"; // 输出格式
$formatter = new LineFormatter($output, $dateFormat);
$stream = new StreamHandler(__DIR__.'/test.log', Logger::DEBUG);
$stream->setFormatter($formatter);
$logger = new Logger('sql');
$logger->pushHandler($stream);
$logger->info('执行语句',['name'=>'hello','age'=>110]); // 执行语句对应 message context对应context sql对应的是channel
生成 按天的日志
require_once 'vendor/autoload.php';
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$dateFormat = "Y-m-d H:i:s";
$output = "[%datetime%] %channel%.%level_name%: %message% %context%\n"; // 输出格式
$formatter = new LineFormatter($output, $dateFormat);
$fileHandler = new RotatingFileHandler("logs/test.log",5); // test-2020-04-16.log
$fileHandler->setFormatter($formatter);
$logger = new Logger('sql');
$logger->pushHandler($fileHandler);
$logger->info('执行语句',['name'=>'hello','age'=>110]); // 执行语句对应 message context对应context sql对应的是channel
https://www.jianshu.com/p/b99dc5c3b760
来源:oschina
链接:https://my.oschina.net/u/4363105/blog/3263926