PHP code example of firehed / simplelogger

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

    

firehed / simplelogger example snippets




tup Syslog logging
$logger = new Firehed\SimpleLogger\Syslog('myapp');

// Output to syslog: "Jun  2 15:55:09 hostname myapp[2712]: foobar"
$logger->error('foobar');

// Output to syslog: "Jun  2 15:55:09 hostname myapp[2712]: Error at /Users/Me/Devel/libraries/simpleLogger/example.php at line 15"
$logger->error('Error at {filename} at line {line}', ['filename' => __FILE__, 'line' => __LINE__]);



tup File logging
$logger = new Firehed\SimpleLogger\File('/tmp/simplelogger.log');

// Output to the file: "[2013-06-02 16:03:28] [info] foobar"
$logger->info('foobar');

// Output to the file: "[2013-06-02 16:03:28] [error] Error at /Users/fred/Devel/libraries/simpleLogger/example.php at line 24"
$logger->error('Error at {filename} at line {line}', ['filename' => __FILE__, 'line' => __LINE__]);

$logger = new \Firehed\SimpleLogger\Stdout();
// or
$logger = new \Firehed\SimpleLogger\Stderr();



og = new Firehed\SimpleLogger\Syslog('myapp');
$syslog->setLevel(Psr\Log\LogLevel::ERROR);  // Define the minimum log level

$file = new Firehed\SimpleLogger\File('/tmp/simplelogger.log');

$logger = new Firehed\SimpleLogger\ChainLogger([$syslog, $file]);
$logger->debug('debug info sent only to the text file');
$logger->error('my error message');
$logger->error('my error message with a {variable}', ['variable' => 'test']);

> $logger->debug('Request complete', ['duration_ms' => $ms]);
> // produces `msg="Request complete" duration_ms=42`
> 

> $logger->debug('Request complete in {duration} ms', ['duration' => $ms]);
> // produces `msg="Request complete in 42 ms"`
> 



irehed\SimpleLogger as SL;

$logger = new SL\ChainLogger([new SL\StdErr()]);
$logger->addLogger(new SL\Syslog('myapp'));
$logger->addLogger(new SL\File('/tmp/simplelogger.log'));

$logger->info('my message');
$logger->error('my error message');
$logger->error('my error message with a {variable}', ['variable' => 'test']);