PHP code example of sebk / small-logger

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 / small-logger example snippets


\Sebk\SmallLogger\Logger::setSwitchLogic(new \Sebk\SmallLogger\SwitchLogic\DefaultSwitchLogic());

\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::setSwitchLogic(new \Sebk\SmallLogger\SwitchLogic\DefaultFileSwitchLogic('/var/log/my-log.log'));

\Sebk\SmallLogger\Logger::setSwitchLogic(new \Sebk\SmallLogger\SwitchLogic\DefaultFileSwitchLogic('/var/log/my-log.log', '/var/log/my-error-log.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'
));

$ sudo apt-get update && apt-get install docker docker-compose
$ docker-compose up -d --build