dadapas/log
Composer 安装命令:
composer require dadapas/log
包简介
Common libraries implementating psr-3 logging interface
关键字:
README 文档
README
This repository implements interfaces related to PSR-3.
Installation
composer require dadapas/log
Usage
If you need a logger, you can use the interface like this:
<?php use Dadapas\Log\{FileSystemAdapter, Log as Logger}; $localAdapter = new \League\Flysystem\Local\LocalFilesystemAdapter( // Determine log directory __DIR__.'/path/to/logs' ); // The FilesystemOperator $filesystem = new \League\Flysystem\Filesystem($localAdapter); $filesysAdapter = new FileSystemAdapter($filesystem); $logger = new Logger(); $logger->setAdapter($filesysAdapter);
To send a logger to an email will be like:
// ... use Dadapas\Log\PHPMailerAdapter; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; $mail = new PHPMailer(true); // $mail->SMTPDebug = SMTP::DEBUG_SERVER; // $mail->isSMTP(); // $mail->Host = 'smtp.example.com'; // $mail->SMTPAuth = true; // ... $adapter = new PHPMailerAdapter($mail); // ... $logger->setAdapter($adapter);
Make a log to the file
// ... try { throw new Exception("An exception has been thrown."); } catch (Exception $e) { // Log to the the error message to file $logger->error($e->getMessage(), $e->getTrace()); } catch (\PHPMailer\PHPMailer\Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }
You can then pick one of the implementations of the interface to get a logger.
If you want to implement the interface, you can require this package and
implement Psr\Log\LoggerInterface in your code. Please read the
specification text
for details.
Test
For making a test just
composer test
License
The licence is MIT for more details click here
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-11