This repository implements interfaces related to PSR-3.
composer require dadapas/log
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.
For making a test just
composer test
The licence is MIT for more details click here