PHP code example of phpgt / logger

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

    

phpgt / logger example snippets


use Gt\Logger\Log;
use Gt\Logger\LogConfig;
use Gt\Logger\LogLevel;
use Gt\Logger\LogHandler\StreamHandler;
use Gt\Logger\LogHandler\FileHandler;

// Send warnings and above to the remote socket.
LogConfig::addHandler(new StreamHandler("/example/remote.sock"), LogLevel::WARNING);
// Send all log types to the local log file.
LogConfig::addHandler(new FileHandler("/var/log/example.log"), LogLevel::DEBUG);

$fileName = "name.txt";
if(file_exists($fileName)) {
        $name = trim(file_get_contents($fileName));
        
        if(empty($name)) {
                Log::error("Empty name loaded");        
        }
        else {
                Log::info("Loaded name: $name");
        }
}
else {
        $name = "you";
        Log::info("Using default name");
}