PHP code example of psr-discovery / log-implementations

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

    

psr-discovery / log-implementations example snippets


use PsrDiscovery\Discover;

// Return an instance of the first discovered PSR-3 Log implementation.
$log = Discover::log();

$log->info('Hello World!');

use PsrDiscovery\Discover;

$logs = Discover::logs();

foreach ($logs as $log) {
    echo sprintf('Discovered %s v%s', $log->getPackage(), $log->getVersion());
}

use PsrDiscovery\Discover;

$log = Discover::log();

if ($log === null) {
    // No suitable Log implementation was discovered.
    // Fall back to a default implementation.
    $log = new DefaultLog();
}

use PsrDiscovery\Discover;

// $log1 !== $log2 (default)
$log1 = Discover::log();
$log2 = Discover::log();

// $log1 === $log2
$log1 = Discover::log(singleton: true);
$log2 = Discover::log(singleton: true);

use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr3\Logs;

// Prefer the a specific implementation of PSR-3 over others.
Logs::prefer('league/container');

// Return an instance of League\Container\Container,
// or the next available from the list of candidates,
// Returns null if none are discovered.
$log = Discover::log();

use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr3\Logs;

// Only discover a specific implementation of PSR-3.
Logs::use('league/container');

// Return an instance of League\Container\Container,
// or null if it is not available.
$log = Discover::log();