dadapas / log
Common libraries implementating psr-3 logging interface
2.0
2022-06-11 16:13 UTC
Requires
- php: >=7.2
- league/flysystem: ^2.4
- phpmailer/phpmailer: ^6.6
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.5
Provides
- psr/log: 1.1
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