I have an class that I autoload through composer to all my other classes:
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class LogStreamer
{
protected static $instance;
public static function getLogger()
{
if(! self::$instance){
self::configureInstance();
}
return self::$instance;
}
private static function configureInstance() {
$logger = new Logger('Q');
$logger->pushHandler(new StreamHandler('/var/log/php/php.log'), Logger::INFO);
self::$instance = $logger;
}
public static function info($message, array $context = []){
self::getLogger()->addInfo($message, $context);
}
public static function debug($message, array $context = []){
self::getLogger()->addDebug($message, $context);
}
When I use it in other classes it looks like this:
public function getOptions() {
LogStreamer::debug("Debug happened in log streamer");
LogStreamer::info("Info happened in log streamer");
And it does print stuff out:
[2018-07-02 09:56:34] Q.DEBUG: Debug happened in log streamer [] [] [2018-07-02 09:56:34] Q.INFO: Info happened in log streamer [] []
But of course I only want info log level in this case. It however, prints both. How can I fix this?