PHP code example of domtomproject / logger-bundle
1. Go to this page and download the library: Download domtomproject/logger-bundle 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/ */
domtomproject / logger-bundle example snippets
use Doctrine\ORM\Mapping as ORM;
use DomTomProject\LoggerBundle\Model\Log;
/**
* @ORM\Entity
*/
class CustomLog extends Log {
/**
* @Column(type="text", nullable=true)
*/
protected $text;
public function __construct() {
parent::__construct();
}
// method for short creating in one line
public static function create(?string $text = null){
$log = new self();
$log->setText($text);
return $log;
}
// setters and getters ...
}
public function testLogAction(){
$logStack = $this->get('domtom_logger.log_stack');
$logStack->add(CustomLog::create('Log that'));
....
// if something failed you can check all logs in stack as failed. Its done automatically if kernel.exception event is called.
if($somethingBroken){
$logStack->failed();
}
}