PHP code example of vista-php / logger

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

    

vista-php / logger example snippets


use Vista\Logger\Logger;
use Vista\Logger\Handlers\StreamHandler;
use Psr\Log\LogLevel;

$logger = new Logger(
    new StreamHandler(__DIR__ . '/app.log', LogLevel::INFO)
);

$logger->info('User {name} logged in', ['name' => 'John']);

final class LogRecord
{
    public readonly string $level;
    public readonly string $message;
    public readonly array $context;
    public readonly DateTimeImmutable $datetime;
}

$logger = new Logger($handlerA, $handlerB);

  use Vista\Logger\Handlers\StreamHandler;
  use Psr\Log\LogLevel;

  $handler = new StreamHandler(
      path: 'php://stdout',
      minLevel: LogLevel::WARNING
  );
  

use Vista\Logger\Handlers\StreamHandler;
use Vista\Logger\Formatters\JsonFormatter;
use Psr\Log\LogLevel;

$handler = new StreamHandler(
    path: __DIR__ . '/app.log',
    minLevel: LogLevel::INFO,
    formatter: new JsonFormatter()
);

use Vista\Logger\Failure\StrictFailureStrategy;

$handler = new StreamHandler(
    path: __DIR__ . '/app.log',
    minLevel: LogLevel::INFO,
    failureStrategy: new StrictFailureStrategy()
);

$logger->info('Hello {name}', ['name' => 'John']);
bash
composer