use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('my_logger'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); $log->warning('This is a warning message'); $log->error('This is an error message');
use Monolog\Logger; use Monolog\Handler\NativeMailerHandler; $log = new Logger('my_logger'); $log->pushHandler(new NativeMailerHandler( 'you@example.com', 'Error occurred', 'admin@example.com', Logger::ERROR )); $log->error('This is an error message');
use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\PDOHandler; $log = new Logger('my_logger'); $log->pushHandler(new RotatingFileHandler('path/to/your.log', 7)); $log->pushHandler(new PDOHandler(new PDO('sqlite:log.db'))); $log->info('This is an info message'); $log->debug('This is a debug message');In this example, we create a new logger instance and add handlers to write log messages to a file and a SQLite database. We then use the logger instance to write info and debug messages to both targets. The package libraries used in this example are Monolog and PDO.