1. Go to this page and download the library: Download gelembjuk/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/ */
gelembjuk / logger example snippets
$logger1 = new Gelembjuk\Logger\FileLogger(
array(
'logfile' => $logfile, // path to your log file (where to write logs)
'groupfilter' => 'group1|group2|group3' // list of groups of events to log. `all` means log everything
));
$errors = new Gelembjuk\Logger\ErrorScreen(
array(
'logger' => $logger1 /*create before*/,
'viewformat' => 'html',
'catchwarnings' => true,
'catchfatals' => true,
'showfatalmessage' => true,
'commonerrormessage' => 'Sorry, somethign went wrong. We will solve ASAP'
)
);
$logger1 = new Gelembjuk\Logger\FileLogger(
array(
'logfile' => '/tmp/log.txt',
'groupfilter' => 'all' // log everything this time
));
// do test log write
$logger1->debug('Test log',array('group' => 'test'));
$logger1->setGroupFilter('group1|group2'); // after this only group1 and group2 events are logged
$logger1->debug('This message will not be in logs as `test` is out of filter',array('group' => 'test'));
class A {
}
class B extends A {
// r;
public function __construct($logger) {
$this->setLogger($logger);
$this->logQ('B object create','construct|B');
}
public function doSomething() {
$this->logQ('doSomething() in B','B');
}
}
class C {
use Gelembjuk\Logger\ApplicationLogger;
public function __construct($logger) {
$this->setLogger($logger);
$this->logQ('C object create','construct|C');
}
public function doOtherThing() {
$this->logQ('oOtherThing() in C','C');
}
}
$b = new B($logger1); // $logger1 is instance of FileLogger
$c = new C($logger1);
$b->doSomething();
$c->doOtherThing();
$errors = new Gelembjuk\Logger\ErrorScreen(
array(
'logger' => $logger1 /*created before*/,
'viewformat' => 'html',
'catchwarnings' => true,
'catchfatals' => true,
'showfatalmessage' => true,
'commonerrormessage' => 'Sorry, somethign went wrong. We will solve ASAP'
)
);
// to catch exceptions on the top level of the app
try {
// do something
} catch (Exception $e) {
$errors->processError($e);
}
// presume there was no exception
// now catch warning
// warning is raised and catched in errors object
// error message displayed to a user
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.