PHP code example of serhii / tiny-logger

1. Go to this page and download the library: Download serhii/tiny-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/ */

    

serhii / tiny-logger example snippets


use Serhii\TinyLogger\Logger;

Logger::setPath('logs/errors.log'); // simple format
Logger::setPath('logs/%s.log', 'errors'); // sprintf format

tiny_log('Some error message');
// Output in file: [2020-01-12 04:09:16] error: Some error message.

tiny_log('Some error message', 'info');
// Output in file: [2020-01-12 04:09:16] info: Some error message.

tiny_log('Some error message', 'debug', 'logs/debug.log');
// If you don't need to set path globally, just pass file path as the third argument to the tiny_log function .

use \Serhii\TinyLogger\Logger;

Logger::new()->error('Some error message');
Logger::new()->info('Some info message');
Logger::new()->debug('Some error message');

tiny_log('Some error message', 'pos'); // just passing option
tiny_log('Some error message', 'pos|error'); // 'pos' option with error type 'error'
tiny_log('Some error message', 'pos|info'); // 'pos' option with error type 'info'

use Serhii\TinyLogger\Logger;

Logger::enablePostRequest('http://my-site.com/webhook');

use Serhii\TinyLogger\JsonFieldValue;
use Serhii\TinyLogger\Logger;

Logger::enablePostRequest('http://my-site.com/webhook', [
    'time' => JsonFieldValue::TIMESTAMP,
    'errorMessage' => 'Error message: ' . JsonFieldValue::MESSAGE,
    'errorType' => JsonFieldValue::ERROR_TYPE,
    'token' => getenv('MY_AUTH_TOKEN')
]);