1. Go to this page and download the library: Download sebk/small-logger 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/ */
\Sebk\SmallLogger\Logger::log(new \Sebk\SmallLogger\Log\BasicLog(
new \DateTime(),
\Sebk\SmallLogger\Contracts\LogInterface::ERR_LEVEL_INFO,
'This is an info log'
));
\Sebk\SmallLogger\Logger::log(new \Sebk\SmallLogger\Log\BasicLog(
new \DateTime(),
\Sebk\SmallLogger\Contracts\LogInterface::ERR_LEVEL_INFO,
'This is an info log'
));
\Sebk\SmallLogger\Logger::log(new \Sebk\SmallLogger\Log\BasicLog(
new \DateTime(),
\Sebk\SmallLogger\Contracts\LogInterface::ERR_LEVEL_ERROR,
'This is an info log'
));
$output = (new \Sebk\SmallLogger\Output\OutputFactory())->get('http', new \Sebk\SmallLogger\Output\Config\HttpConfig('localhost', 8080, false));
namespace App\Logs;
class HttpSwitcherLogic implements \Sebk\SmallLogger\Contracts\SwitchLogicInterface
{
protected \Sebk\SmallLogger\Contracts\StreamInterface $stream;
public function __construct(\Sebk\SmallLogger\Output\Config\HttpConfig $config)
{
$this->stream = new \Sebk\SmallLogger\Stream\Stream(
new \Sebk\SmallLogger\Formatter\JsonFormatter(),
(new \Sebk\SmallLogger\Output\OutputFactory())->get('http', $config)
);
}
public function getStream(\Sebk\SmallLogger\Contracts\LogInterface $log, array $data = []) : \Sebk\SmallLogger\Contracts\StreamInterface
{
$this->stream;
}
}
\Sebk\SmallLogger\Logger::setSwitchLogic(new HttpSwitcher(
new \Sebk\SmallLogger\Output\Config\HttpConfig(
'logstash.my-domain.com',
8080,
true
)
));
\Sebk\SmallLogger\Logger::log(new \Sebk\SmallLogger\Log\BasicLog(
new \DateTime(),
\Sebk\SmallLogger\Contracts\LogInterface::ERR_LEVEL_ERROR,
'This an error'
));