Access Underlying Monolog Instance used by Laravel


Snippet

Access the underlying Monolog instance used by Laravel with the following snippet:

$monolog = \Log::getMonolog();

Example Use Case

For example, when using the spatie/image-optimizer package, there is an option to include a logger via a class that implements Psr\Log\LoggerInterface. In the case of a Laravel project it is convenient to output this log data directly to the laravel.log file by utlizing the existing Monolog instance directly:

use Spatie\ImageOptimizer\OptimizerChainFactory;

$optimizerChain = OptimizerChainFactory::create();

$optimizerChain
   ->useLogger(\Log::getMonolog())
   ->optimize($pathToImage);


Comments:


Gravatar of Kyle Jones

Knowledge Base is a repository for various notes, guides, and thoughts on a wide range of IT related topics. Read more...

Sponsored By:


Web development services by Say Web Solutions. Visit website.