Last active
September 19, 2016 20:12
-
-
Save s-chizhik/522fe31208250084ab0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Be sure that https://github.com/bramus/monolog-colored-line-formatter is installed | |
* | |
* composer require bramus/monolog-colored-line-formatter '~2.0' | |
*/ | |
class L { | |
private static $logger; | |
private function __construct(){} | |
private function __clone(){} | |
private static function getConfiguredLogger() | |
{ | |
$handler = new Monolog\Handler\StreamHandler(sys_get_temp_dir() . '/logs.txt'); | |
$handler->setFormatter(new Bramus\Monolog\Formatter\ColoredLineFormatter()); | |
$logger = new Monolog\Logger(__CLASS__); | |
$logger->pushHandler($handler); | |
return $logger; | |
} | |
protected static function getInstance() | |
{ | |
return !empty(self::$logger) | |
? self::$logger | |
: self::$logger = self::getConfiguredLogger(); | |
} | |
public static function debug($message, $context = []) { self::getInstance()-> debug($message, $context); } | |
public static function info($message, $context = []) { self::getInstance()-> info($message, $context); } | |
public static function notice($message, $context = []) { self::getInstance()-> notice($message, $context); } | |
public static function warning($message, $context = []) { self::getInstance()-> warning($message, $context); } | |
public static function error($message, $context = []) { self::getInstance()-> error($message, $context); } | |
public static function critical($message, $context = []) { self::getInstance()-> critical($message, $context); } | |
public static function alert($message, $context = []) { self::getInstance()-> alert($message, $context); } | |
public static function emergency($message, $context = []) { self::getInstance()->emergency($message, $context); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment