Capturing logs
You can send your application logs to Insights either by sending them to
Honeybadger from your infrastructure
or if you are using Monolog, you can register Honeybadger’s
LogEventHandler class as a handler:
$logger = new Monolog\Logger('my-logger');$honeybadger = Honeybadger\Honeybadger::new([ 'api_key' => 'my-api-key']);$logger->pushHandler(new Honeybadger\LogEventHandler($honeybadger));$logger->info('An info message');$logger->info('An info message with context data', ["some-key" => "some-value"]);$logger->error('An error message');You can send an optional second argument to the LogEventHandler constructor to
specify the minimum log level to be sent to Honeybadger. The default is
Monolog\Logger::INFO.
new Honeybadger\LogEventHandler($honeybadger, Monolog\Logger::DEBUG);This will send all log messages to Insights, where they will be displayed in the Insights section of your dashboard.
Using Laravel or Lumen
Section titled “Using Laravel or Lumen”If you are using Laravel or Lumen,
register a custom channel
in your config/logging.php, making use of the HoneybadgerLogEventDriver:
'channels' => [ // ... 'honeybadger' => [ 'driver' => 'custom', 'via' => Honeybadger\HoneybadgerLaravel\HoneybadgerLogEventDriver::class, 'name' => 'honeybadger', 'level' => 'info', ], ],Now you can write log messages as normal with Laravel’s log facade, and they’ll show up in Honeybadger Insights:
Log::channel('honeybadger')->info('An info message');Log::channel('honeybadger')->error('An error message with context', ["some-key" => "some-value"]);Add this custom channel to your default stack and voilà, all your log messages will appear in Honeybadger Insights:
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'honeybadger'], 'ignore_exceptions' => false, ], // ... ],