for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Sulao\YiiHoneybadger;
use Throwable;
use Yii;
use yii\log\Target as YiiTarget;
class Target extends YiiTarget
{
protected ?Component $component = null;
public function init()
parent::init();
$this->component = Yii::$app->honeybadger;
}
/**
* Exports the log messages to Honeybadger
*
* This method iterates through the collected log messages and sends them to Honeybadger.
* It handles both exceptions and error messages, sending them with appropriate context.
*/
public function export()
foreach ($this->messages as $message) {
[$context, , $category , , $traces] = $message;
if ($context instanceof Throwable) {
$this->component?->notify($context);
} elseif (is_string($context)) {
$data = [
'title' => $category,
'message' => $context,
];
if (isset($traces[0]['file'])) {
$data['file'] = $traces[0]['file'];
if (isset($traces[0]['line'])) {
$data['line'] = $traces[0]['line'];
$this->component?->customNotification($data);
* Generates the context information to be logged.
* The default implementation will dump user information, system variables, etc.
* Here returns an empty string.
* @return string the context information. If an empty string, it means no context information.
protected function getContextMessage()
return '';