use Monolog\Logger; use Monolog\Handler\StreamHandler; // Create a logger instance $log = new Logger('my_logger'); // Create a stream handler $streamHandler = new StreamHandler('path/to/your.log', Logger::ERROR); // Add the stream handler to the logger instance $log->pushHandler($streamHandler); // Add an error message to the log $log->addError('Oops! Something went wrong!');
use Monolog\Logger; use Monolog\Handler\BrowserConsoleHandler; // Create a logger instance $log = new Logger('my_logger'); // Create a browser console handler $consoleHandler = new BrowserConsoleHandler(Logger::DEBUG); // Add the console handler to the logger instance $log->pushHandler($consoleHandler); // Add an error message to the browser console $log->addError('Oops! Something went wrong!');In this example, we create a Logger instance and a BrowserConsoleHandler that writes logs to the browser console. We then add the BrowserConsoleHandler to the Logger instance and use the addError method to log an error message. This log entry will only be written to the console for DEBUG log level or higher. Package library: Monolog.