标签:shel text extension custom default origin dia -- file
One Efficient & Light & Simple high performance PHP log implemention of PSR-3
一个高性能、简约、轻量的psr-3接口实现日志PHP类库
Inherently cached message record using PHP object attribute.
天然的基于Logger实例缓存特性
$ composer require logger-one/logger-one
FileHandler
create a log file named for %Y%m%d
and appendix .log
at LoggerOne
root folder, ervery message as line with the original$logger = LoggerOne\Logger::getInstance(); // Strongly recommend
$message = ‘test log message {placeholder1} {placeholder2}‘;
$replacements = [‘placeholder1‘ => ‘Foo‘, ‘placeholder2‘ => ‘bar‘];
$logger->info($message, $replacements);
FileHandler
default path$logFile = ‘./tmp/loggerOne.log‘; // Your path where you want
$handler = new LoggerOne\Handler\FileHandler($logFile);
$logger->setHandler($handler);
$logger->info($message);
$handler = new LoggerOne\Handler\FooHandler();
$handler = new LoggerOne\Formatter\BarFormatter();
$logger->setHandler($handler)->setFormatter($formatter);
$logger->info(‘some test log message‘);
flush
method will write all previous message by handler...
$logger->info(‘some test log message‘)->flush();
...
MySQLHandler.php
in LoggerOne\Handler
folder<?php
namespace LoggerOne\Handler;
class MySQLHandler implements Handler
{
protected $db;
protected $table_name;
public function __construct(string $table_name, object $dbHandle = null)
{
$this->table_name = $table_name;
$this->db = $dbHandle;
}
public function write($messages)
{
$batchData = [];
foreach ($messages as $level => $message) {
$batchData[] = [‘level‘ => $level, ‘message‘ => $message, ‘created‘ => time()];
}
$this->db->insertBatch($this->table_name, $batchData);
}
}
MySQLHandler.php
$logger = new LoggerOne\Logger();
$handler = new LoggerOne\Handler\MysqlHandler($yourLogTableName, $yourDbHandle);
$logger->setHandler($handler);
$logger->info(‘some test log message‘);
标签:shel text extension custom default origin dia -- file
原文地址:http://www.cnblogs.com/lijiebin/p/7046067.html