PHP code example of kuran / slogger

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

    

kuran / slogger example snippets



Kuran\SLOGGER\{Logger, ErrorLevel, Managers\FileManager};

/* Instantiate the class.
* Then create a new Manager. The FileManager nd an array for context.
*/
$log->alert(
    message: "Test message for the file {:file}",
    context: array(
        ":file" => __FILE__,
        ":extras" => array(
            ["name" => "Admin", "username" => "admin"],
            ["name" => "Root", "username" => "root"]
            )
        )
);

    __construct(array $managers = array())

    setManagers(managers: = array(
        new FileManager(filePath: 'debug.log', level: ErrorLevel::Debug, formater: null),
        new FileManager(filePath: 'errors.log', level: ErrorLevel::Error, formater: null)
        )
    );

    addManager(ManagerInterface $manager);

__construct(
        filePath: = 'app.log',
        level: = ErrorLevel::ERROR,
        formater: = null)

    setFormater(FormaterInterface $formater)

    $manager = new FileManager(
        filePath: "path/to/logfile.log",
        level: ErrorLevel::INFO, // Set the minimum Error level for this manager.
        formater: new LineFormater()
    )

    // Setting multiple managers with different Error Levels

    $log = new Logger();

    $errorManager = new FileManager(
        filePath: "error.log",
        level: ErrorLevel::ERROR
    );
    $debugManager = new FileManager(
        filePath: "debug.log",
        level: ErrorLevel::DEBUG
    );

    //set the Manager list to $errorManager and $debugManager
    $log->setManagers(array($errorManager, $debugManager));

    // add $manager to the list of managers
    $log->addManager($manager);

enum ErrorLevel: int
{
    case EMERGENCY = 800; //ErrorLevel::EMERGENCY
    case ALERT     = 700; //ErrorLevel::ALERT
    case CRITICAL  = 600; //ErrorLevel::CRITIAL
    case ERROR     = 500; //ErrorLevel::ERROR
    case WARNING   = 400; //ErrorLevel::WARNING
    case NOTICE    = 300; //ErrorLevel::NOTICE
    case INFO      = 200; //ErrorLevel::INFO
    case DEBUG     = 100; //ErrorLevel::DEBUG
}

    ErrorLevel::fromValue(700); // ErrorLevel::ALERT
    ErrorLevel::fromName('Notice'); // ErrorLevel::NOTICE

    __construct(
        string $format = null,
        string $timeFormat = null
        )

$formater = new LineFormater(
    format: "{:date} {:errorLevel} {:message} {:context}",
    timeFormat: "m-d-Y H:i"
);