1. Go to this page and download the library: Download stange/slog 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/ */
stange / slog example snippets
use \stange\logging\Slog;
$log = new Slog();
$log->log('Scotty, beam me up!');
use \stange\logging\Slog;
$log = new Slog();
$log->log('test message');
$log->debug('Debug');
$log->info('Info');
$log->warning('Warning');
$log->error('Error');
$log->emergency('Emergency');
$log->success('Success');
use \stange\logging\Slog;
$log = new Slog([
'colors' => FALSE
]);
//You can disable colors at runtime too
//$log->useColors(FALSE);
$log->debug('Debug');
use \stange\logging\Slog;
$log = new Slog([
'file'=>'out.log'
]);
$log->log('Log to a file (and to stdout)');
use \stange\logging\Slog;
$log = new Slog([
'file' => 'out.log',
'echo' => FALSE
]);
$log->log("No stdout log, file only");
use \stange\logging\Slog;
$log = new Slog([
'tagId'=>'@@@'
]);
$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');
$log->log('tagTwo@@@This is another tagged message with the tagTwo');
$log = new Slog([
'tagId' => '@@@', //Set the tag identifier to @@@
'tags' => 'tagOne' //Log messages only from tagOne
]);
$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');
//The next message will not be logged since we specified that only messages
//containing the tag "tagOne" will be logged.
$log->log('tagTwo@@@This is another tagged message with the tagTwo');
$log = new Slog([
'tagId' => '@@@', //Set the tag identifier to @@@
'tags' => ['tagOne','tagTwo'] //Log messages from tagOne AND tagTwo
]);
$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');
$log->log('tagTwo@@@This is another tagged message with the tagTwo');
namespace myProject{
/**
* Add the loggable interface to indicate to other class methods
* that this class has logging capabilities.
*/
use \stange\logging\slog\iface\Loggable as LoggableInterface;
class MyClass implements LoggableInterface{
//Make the class "Loggable" by using the loggable trait
use \stange\logging\slog\traits\Loggable;
public function doStuff(){
$this->log('stuff@@@Doing stuff!');
}
public function doOtherStuff(){
$this->log('otherStuff@@@Doing other stuff!','info');
}
}
class MyOtherClass implements LoggableInterface{
use \stange\logging\slog\traits\Loggable;
public function doSomething(){
$this->log('Doing something!','success');
}
}
}
namespace myProject;
use \stange\logging\Slog();
$log = new Slog([
'tagId' => '@@@',
'tags' => 'stuff'
]);
$myClass = new MyClass();
$myOtherClass = new MyOtherClass();
$myClass->setLog($log);
$myOtherClass->setLog($log);
$myClass->doStuff();
$myClass->doingOtherStuff();
$myOtherClass->doSomething();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.