PhpMonolog is a PHP logging library that helps developers create a log for their PHP application. It makes use of a logger to pass messages to where they can be stored, either in a local file or a remote server.
Examples: 1. Writing logs to a local file:
use Monolog\Logger; use Monolog\Handler\StreamHandler;
$log = new Logger('my_log'); $log->pushHandler(new StreamHandler('path/to/log/file.log', Logger::INFO);
$log->info('This is a log message');
// The log message is written to the file located at path/to/log/file.log.
2. Writing logs to a remote server using Syslog:
$log = new Logger('my_log'); $log->pushHandler(new SyslogHandler('my_app', 'local0', Logger::INFO));
$log->info('This is a log message');
// The log message is sent to a remote syslog server.
3. Logging exceptions with stacktraces:
$log = new Logger('my_log'); $log->pushHandler(new StreamHandler('path/to/log/file.log', Logger::ERROR));
try { // some code that may throw an exception } catch (Exception $e) { $log->error('Caught exception: ' . $e->getMessage(), ['exception' => $e]); }
// An error log is written to the file located at path/to/log/file.log, // including the exception message and its stacktrace.
Package library: Monolog
PHP Monolog Logger::Info - 1 examples found. These are the top rated real world PHP examples of Monolog\Logger::Info extracted from open source projects. You can rate examples to help us improve the quality of examples.