PHPackages                             mitrm/yii2-sentry-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. mitrm/yii2-sentry-log

ActiveYii2-extension[Logging &amp; Monitoring](/categories/logging)

mitrm/yii2-sentry-log
=====================

A Yii2 component for Sentry allowing data arrays passing through Yii2 logging methods

086

Since Jan 20Compare

[ Source](https://github.com/mitrm/yii2-sentry-log)[ Packagist](https://packagist.org/packages/mitrm/yii2-sentry-log)[ RSS](/packages/mitrm-yii2-sentry-log/feed)WikiDiscussions Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 sentry log
===============

[](#yii2-sentry-log)

Yii2 Sentry component allowing for unified array format passing parameters to Sentry log target and other log targets. The ability to pass arrays as the log message is suitable practice for those who want to use Logstash, ElasticSearch, etc. for getting statistical inferences of these data later on.

Install
-------

[](#install)

```
php composer.phar require --prefer-dist mitrm/yii2-sentry-log "dev-master"

```

In config file:

```
'bootstrap' => ['log', 'raven'],
'components' => [
    'raven' => [
        'class' => 'mitrm\sentry\ErrorHandler',
        'dsn' => '', // Sentry DSN
    ],
    'log' => [
        'targets' => [
            [
                'class' => 'mitrm\sentry\Target',
                'levels' => ['error', 'warning'],
                'dsn' => '', // Sentry DSN
            ]
        ],
    ],
]
```

If application doesn't have `raven` component, the component will not try to send messages to sentry. This is useful for development environments, for example.

Usage
-----

[](#usage)

Exceptions and PHP errors are caught without effort. Standart `Yii::(error|warning|info|trace)` logging works as usual, but you also can use the following format:

```
Yii::warning([
    'msg' => 'SomeWarning', // event name that will be sent to Sentry
    'data' => [ // extra data for the event
        'userId' => Yii::$app->user->id,
        'someDataOnWarningSituation' => $controller->state,
        'modelThatCausedFailure' => $model->attributes,
    ],
], 'eventCategory');
```

Or you can replace this with `Log::warning` as in the exception example below, since the exception argument is not required. Notice that `eventCategory` is not sent to Sentry and is used only for log messages routing and filtering.

Wherever you need to log a caught exception with stacktrace and additional data, use

```
use sheershoff\sentry\Log;
// some code here
try{
    $model1->save();
}catch (\Exception $e){
    Log::warning([
        'msg' => 'ExceptionWarning', // event name that will be sent to Sentry
        'data' => [ // extra data for the event
            'userId' => Yii::$app->user->id,
            'someDataOnWarningSituation' => $controller->state,
            'modelThatCausedFailure' => $model->attributes,
        ],
    ], 'exceptionCategory', $e);
}
```

There are proxy methods in `Log` for the four Yii static methods: `error`, `warning`, `info`, `trace`. If `$e` is not null the component expects that it is an exception and after calling the corresponding Yii method also captures the exception for Sentry.

Also, the following use cases are possible:

```
SentryHelper::extraData($task->attributes);
throw new Exception('unknown task type');
```

Or just capture a message with full stacktrace:

```
try {
    throw new Exception('FAIL');
} catch (Exception $e) {
    SentryHelper::captureWithMessage('Fail to save model', $e);
}
```

Other log targets
-----------------

[](#other-log-targets)

To use the power of the component you should keep in mind that other log targets will receive arrays instead of strings in the log message. You can create a proxy class, redefining `formatMessage` method of the parent LogTarget, e.g.:

```
namespace common\components;
use Yii;
class SyslogJsonTarget extends \yii\log\SyslogTarget
{
	/**
	 * @inheritdoc
	 */
	public function formatMessage($message)
	{
		list($text, $level, $category, $timestamp) = $message;
		$level = \yii\log\Logger::getLevelName($level);
		if (!is_string($text)) {
			$text = \yii\helpers\Json::encode($text);
		} else {
			$text = \yii\helpers\Json::encode(['rawstring' => $text]);
		}
		$prefix = $this->getMessagePrefix($message);
		return "{$prefix}[$level][$category] $text";
	}
}
```

Data precautions
----------------

[](#data-precautions)

- Avoid passing resources and objects that can not be serialized in the array or rewrite formatMessage to handle that, e.g. trying to serialize PDO instance will raise fatal PHP error. Native Yii log targets will try to serialize that. One can check  to see how it sanitizes and handles these cases and use it's static methods.
- Also check how raven can filter out private data such as password or sensitive financial requisites.

Inspired by
-----------

[](#inspired-by)

-
-
-

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b8ac7c311b77a2512bd5a04d2c9bcf67f542c853e922f2d43ea3306b5691a4b?d=identicon)[mitrm](/maintainers/mitrm)

---

Top Contributors

[![mitrm](https://avatars.githubusercontent.com/u/9912491?v=4)](https://github.com/mitrm "mitrm (2 commits)")

### Embed Badge

![Health badge](/badges/mitrm-yii2-sentry-log/health.svg)

```
[![Health](https://phpackages.com/badges/mitrm-yii2-sentry-log/health.svg)](https://phpackages.com/packages/mitrm-yii2-sentry-log)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M263](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M317](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
