PHP code example of khalyomede / syslog

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

    

khalyomede / syslog example snippets


$log->host('some.vendor.com')
  ->port(92883)
  ->facility(22)
  ->source('my.company.io')
  ->device('website')
  ->processus('price-index');

$log->debug('page loaded in 3.840 s');

use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$log->debug("user created in 5ms");

use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$message = "user {username} created successfuly";

$log->info($message, ['username' => 'johndoe']);

use Khalyomede\Syslog;
use Psr\Log\LogLevel;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$log->log(LogLevel::ERROR, "the user could not be created because: this username already exists");

$log->log('error' 'the user could not be created because: this username already exists');

use Khalyomede\Syslog;
use Psr\Log\LogLevel;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$message = "user {username} created successfuly";

$log->log(LogLevel::ERROR, $message, ['username' => 'johndoe']);

use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->date(new DateTime('2017-11-29 04:34:09', new DateTimeZone('Europe/Paris')));

$log->emergency('detected forbidden access to database');

use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->identifier('AZXT6');

$log->debug("database optimized in 33.09 s.");

$log->deleteIdentifier();

public function alert(string $message, array $context = []): Syslog

public function critical(string $message, array $context = []): Syslog

public function date(DateTime $date): Syslog

public function debug(string $message, array $context = []): Syslog

public function deleteIdentifier(): Syslog

public function device(string $device): Syslog

public function emergency(string $message, array $context = []): Syslog

public function error(string $message, array $context = []): Syslog

public function facility(int $facility): Syslog

public function host(string $host): Syslog

public function source(string $source): Syslog

public function info(string $message, array $context = []): Syslog

public function log(string $level, string $message, array $context = []): Syslog

public function notice(string $message, array $context = []): Syslog

public function port(int $port): Syslog

public function processus(string $processus): Syslog

public function source(string $source): Syslog

public function warning(string $message, array $context = []): Syslog

use Khalyomede\Syslog;

$log = new Syslog;

$log->prototype('oneHourAgo', function() {
  $this->date->sub(new DateInterval('PT1H'));

  return $this;
});

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->date(new DateTime)
  ->oneHourAgo();

$log->info('test');