PHP code example of elementary / logger-trait
1. Go to this page and download the library: Download elementary/logger-trait 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/ */
elementary / logger-trait example snippets
use elementary\logger\traits\LoggerGetInterface;
use elementary\logger\traits\LoggerTrait;
use Psr\Log\LoggerAwareInterface;
class Example implements LoggerGetInterface, LoggerAwareInterface
{
use LoggerTrait;
public function doSomeThing()
{
// do some thing
$this->getLogger()->info('do some thing');
}
}
$ex = new Example();
// In this case, the message will be sent to `\Psr\Log\NullLogger`
$ex->doSomeThing();
// Now message will be send to Graylog
$ex->setLogger(new \Gelf\Logger($publisher, $facility));
$ex->doSomeThing();