1. Go to this page and download the library: Download qingbing/zf-log 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/ */
qingbing / zf-log example snippets
$logger = Object::create([
'class' => Logger::class,
'channel' => 'log'
]);
/* @var Logger $logger */
$logger->emergency('I am emergency.');
$logger->alert('I am alert.');
$logger->critical('I am critical.');
$logger->error('I am error.');
$logger->warning('I am warning.');
$logger->notice('I am notice.');
$logger->info('I am info.');
$logger->debug('I am debug.');
$logger = Object::create([
'class' => Logger::class,
'channel' => 'log'
]);
/* @var Logger $logger */
// 文件日志处理机
$flusher = new FileFlusher(new Formatter());
$flusher->acceptTypes = [
Logger::INFO,
Logger::WARNING,
Logger::CRITICAL,
];
$logger->addFlusher($flusher);
// 流式日志处理
$flusher = new StreamFlusher(new class extends AFormatter
{
/**
* @describe 格式化一个日志记录
*
* @param array $record
*
* @return mixed
*/
public function format(array $record)
{
return json_encode($record, JSON_UNESCAPED_UNICODE);
}
});
$flusher->acceptTypes = [
Logger::WARNING,
Logger::CRITICAL,
];
// 流式消息处理机
$logger->addFlusher($flusher);
$logger->emergency('I am emergency.');
$logger->alert('I am alert.');
$logger->critical('I am critical.');
$logger->error('I am error.');
$logger->warning('I am warning.');
$logger->notice('I am notice.');
$logger->info('I am info.');
$logger->debug('I am debug.');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.