PHP code example of auron-consulting-oss / php-console-logger

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

    

auron-consulting-oss / php-console-logger example snippets


// No timestamps
$consoleLogger = new AuronConsultingOSS\Logger\Console(false);

// With timestamps (default)
$console = new AuronConsultingOSS\Logger\Console(true);

[ ... ]

// Then, simply use like a regular PSR-3 logger
$console->info('Whatever', ['extra_stuff' => 'maybe']);
 example/example.php


re 'ExampleClass.php';

$console = new AuronConsultingOSS\Logger\Console();

// Straight string messages
$console->info('This is an info message');
$console->notice('This is a notice message');
$console->debug('This is a debug message');
$console->warning('This is a warning message');
$console->alert('This is an alert message');
$console->error('This is an error message');
$console->emergency('This is an emergency message');
$console->critical('This is a critical message');

// Messages with exceptions and traces
try {
    $exampleClass = new ExampleClass();
    $exampleClass->prepare();
} catch (Exception $ex) {
    $console->error('Whoopsies', ['exception' => $ex]);
}

// Messages with random data
$console->warning('Some data on context', ['foo' => 'bar']);

// Messages with random data plus exception
$console->alert('Some data on context, as well as an exception', ['foo' => 'bar', 'exception' => $ex]);

// Passing on an exception directly as a message (or any object that implements __toString)
$console->debug($ex);

// Since we're PSR-3, we can be injected on objects that understand LoggerAwareInterface - example class does
$exampleClass->setLogger($console);
$exampleClass->runLoggerAwareExample();

// You get the idea
$console->notice('That\'s it.');
$console->info('C\'est fini.');