use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); $log->warning('User failed to login');
use Monolog\Logger; use Monolog\Handler\StreamHandler; use Psr\Log\LoggerInterface; class MyClass { private $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function doSomething() { $this->logger->info('Doing something...'); } } $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::INFO)); $myClass = new MyClass($log); $myClass->doSomething();Both of these examples use different packages: Monolog and Psr\Log. The Logger class in the Monolog package is used to create a logger instance and log messages to a file or other handlers. The Psr\Log\LoggerInterface is a standard interface for logging libraries, which allows developers to switch between different logging libraries without changing their code.