use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('name'); $log->pushHandler(new StreamHandler('/path/to/your.log', Logger::WARNING)); $log->warning('Foo');
use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\DeduplicationHandler; use Monolog\Handler\FirePHPHandler; use Monolog\Handler\NativeMailerHandler; use Monolog\Formatter\LineFormatter; use Monolog\Processor\IntrospectionProcessor; use Monolog\Processor\UidProcessor; $log = new Logger('name'); $handler1 = new RotatingFileHandler('/path/to/your.log'); $handler2 = new DeduplicationHandler($handler1); $handler3 = new FirePHPHandler(); $handler4 = new NativeMailerHandler('you@example.com', 'Error Alert', 'admin@example.com', Logger::CRITICAL); $lineFormatter = new LineFormatter(null, null, false, true); $handler1->setFormatter($lineFormatter); $log->pushHandler($handler1); $log->pushHandler($handler2); $log->pushHandler($handler3); $log->pushHandler($handler4); $log->pushProcessor(new IntrospectionProcessor()); $log->pushProcessor(new UidProcessor(32)); $log->warning('Foo');In this example, the Logger is created with a name of 'name', and four different handlers are added to it. The first handler is a RotatingFileHandler that writes log messages to a file at '/path/to/your.log'. The second handler is a DeduplicationHandler that deduplicates log messages to avoid spamming. The third handler is a FirePHPHandler that logs messages to the Firefox console. The fourth handler is a NativeMailerHandler that sends error notifications to an email address. Two processors are also added to the Logger - an IntrospectionProcessor that adds file and line number information to log messages, and a UidProcessor that adds a unique identifier to each message. Finally, a warning message is logged using the Logger's warning method. Overall, the Logger package provides a flexible and customizable logging solution for PHP developers, allowing them to easily configure how log data is stored and displayed in their applications.