PHPackages                             cinghie/yii2-logger - 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. cinghie/yii2-logger

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

cinghie/yii2-logger
===================

Yii2 Logger to create log to Database or File in a Yii2 site.

02231PHP

Since Jan 31Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/cinghie/yii2-logger)[ Packagist](https://packagist.org/packages/cinghie/yii2-logger)[ RSS](/packages/cinghie-yii2-logger/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 Logger
===========

[](#yii2-logger)

[![License](https://camo.githubusercontent.com/b0492d9efd59be10a4fab25a5c438d60d13d359e92dc5262105ec0047f7c1622/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f63696e676869652f796969322d6c6f676765722e737667)](https://camo.githubusercontent.com/b0492d9efd59be10a4fab25a5c438d60d13d359e92dc5262105ec0047f7c1622/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f63696e676869652f796969322d6c6f676765722e737667)[![Latest Stable Version](https://camo.githubusercontent.com/293e8d05d30ad0747ad27924b9dfe45b2d3c53a0a40705a47b09c5dcedb58a3a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f63696e676869652f796969322d6c6f676765722e737667)](https://camo.githubusercontent.com/293e8d05d30ad0747ad27924b9dfe45b2d3c53a0a40705a47b09c5dcedb58a3a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f63696e676869652f796969322d6c6f676765722e737667)[![Latest Release Date](https://camo.githubusercontent.com/44ed0d50bafa639ce2eba2954538aaafd043e30b85029cd469b9641561cb5d28/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f63696e676869652f796969322d6c6f676765722e737667)](https://camo.githubusercontent.com/44ed0d50bafa639ce2eba2954538aaafd043e30b85029cd469b9641561cb5d28/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f63696e676869652f796969322d6c6f676765722e737667)[![Latest Commit](https://camo.githubusercontent.com/d155f34eed5dd5c51d563f2980a8e21c7d2fe7ae4a9b59490dfeb30a3fef0d75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f63696e676869652f796969322d6c6f676765722e737667)](https://camo.githubusercontent.com/d155f34eed5dd5c51d563f2980a8e21c7d2fe7ae4a9b59490dfeb30a3fef0d75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f63696e676869652f796969322d6c6f676765722e737667)[![Total Downloads](https://camo.githubusercontent.com/7823baf0c87fd59d0b53016cd398df7e45d64ab67b8eac1a118d745e5bd8d4f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63696e676869652f796969322d6c6f676765722e737667)](https://packagist.org/packages/cinghie/yii2-logger)

Yii2 extension to log actions (create, update, delete) to the database. It includes a log list, single log view, and a **timeline** with filters by user, action, model, and date.

---

Installation
------------

[](#installation)

### 1. Install the package

[](#1-install-the-package)

```
composer require cinghie/yii2-logger "*"
```

Or add to your `composer.json`:

```
"require": {
    "cinghie/yii2-logger": "*"
}
```

### 2. Update database schema

[](#2-update-database-schema)

```
php yii migrate/up --migrationPath=@vendor/cinghie/yii2-logger/migrations
```

---

Configuration
-------------

[](#configuration)

Register the module in `config/web.php` (or `common/config/main.php`):

```
use cinghie\logger\Logger;

'modules' => [
    'logger' => [
        'class' => Logger::class,
        'bootstrap' => 'bootstrap',        // 'bootstrap' | 'bootstrap4' | 'bootstrap5'
        'roles' => ['admin'],              // RBAC roles allowed to access the module
        'showTitles' => false,             // show h1 titles in module views
    ],
],
```

- **bootstrap**: if set to `bootstrap4` and you have `cinghie/yii2-adminlte3` installed, the timeline uses the AdminLTE 3 widget.
- **roles**: array of RBAC roles allowed to access index, timeline, and view.
- **showTitles**: set to `true` to show the h1 title on module pages.

---

Usage examples
--------------

[](#usage-examples)

### 1. Log an action in a controller

[](#1-log-an-action-in-a-controller)

After creating, updating, or deleting a model, save a record to `Loggers`:

```
use cinghie\logger\models\Loggers;
use yii\helpers\Url;

// Example: after saving a model (e.g. Contact)
public function actionCreate()
{
    $model = new Contact();
    if ($model->load(Yii::$app->request->post()) && $model->save()) {

        $logger = new Loggers();
        $logger->entity_name = 'Contact';
        $logger->entity_id = $model->id;
        $logger->entity_model = 'Contact';
        $logger->entity_url = '/contacts/contacts/view';
        $logger->action = 'create';
        $logger->data = $model->getFullName(); // or any descriptive text
        $logger->created_by = Yii::$app->user->id;
        $logger->ip = Yii::$app->request->userHost;
        $logger->save(false);

        return $this->redirect(['view', 'id' => $model->id]);
    }
    // ...
}
```

### 2. Log for update and delete

[](#2-log-for-update-and-delete)

```
// After update
$logger = new Loggers();
$logger->entity_name = 'Order';
$logger->entity_id = $model->id;
$logger->entity_model = 'Order';
$logger->entity_url = '/commerce/order/view';
$logger->action = 'update';
$logger->data = 'Status: ' . $model->status;
$logger->created_by = Yii::$app->user->id;
$logger->ip = Yii::$app->request->userHost;
$logger->save(false);

// After delete (you can pass id and data before deleting the model)
$logger = new Loggers();
$logger->entity_name = 'Product';
$logger->entity_id = $id;
$logger->entity_model = 'Product';
$logger->entity_url = '/commerce/product/index';
$logger->action = 'delete';
$logger->data = $model->name;
$logger->created_by = Yii::$app->user->id;
$logger->ip = Yii::$app->request->userHost;
$logger->save(false);
```

### 3. Helper method on the model (optional)

[](#3-helper-method-on-the-model-optional)

To avoid repeating the same code, add a method to your model or a trait:

```
// e.g. in app\models\Contact or in a trait
use cinghie\logger\models\Loggers;

public function logAction($action, $data = '')
{
    $logger = new Loggers();
    $logger->entity_name = 'Contact';
    $logger->entity_id = $this->id;
    $logger->entity_model = 'Contact';
    $logger->entity_url = '/contacts/contacts/view';
    $logger->action = $action; // 'create' | 'update' | 'delete'
    $logger->data = $data ?: $this->getFullName();
    $logger->created_by = Yii::$app->user->id;
    $logger->ip = Yii::$app->request->userHost;
    $logger->save(false);
}

// In controller after $model->save():
$model->logAction('create');
```

### 4. Links to module pages

[](#4-links-to-module-pages)

- **Log list (grid)**: `/logger/loggers/index`
- **Timeline (with filters)**: `/logger/loggers/timeline`
- **Single log detail**: `/logger/loggers/view?id=123`

Example links in a menu or view:

```
use yii\helpers\Html;
use yii\helpers\Url;

echo Html::a('Log', ['/logger/loggers/index']);
echo Html::a('Timeline', ['/logger/loggers/timeline']);
```

### 5. Timeline widget in a custom view

[](#5-timeline-widget-in-a-custom-view)

To show the timeline in another view, use the module’s widget (it automatically picks Bootstrap or AdminLTE3 based on config):

```
use cinghie\logger\widgets\Timeline;
use cinghie\logger\models\Loggers;
use cinghie\logger\models\LoggersSearch;

// Fetch data (e.g. last 7 days)
$items = Loggers::find()
    ->where(['>=', 'created_date', date('Y-m-d', strtotime('-7 days'))])
    ->orderBy('created DESC')
    ->limit(100)
    ->all();

$days = Loggers::find()
    ->select('created_date')
    ->where(['>=', 'created_date', date('Y-m-d', strtotime('-7 days'))])
    ->groupBy('created_date')
    ->orderBy('created_date DESC')
    ->asArray()
    ->all();

$searchModel = new LoggersSearch();
$userNames = $searchModel->getUsersSelect2();

echo Timeline::widget([
    'days' => $days,
    'items' => $items,
    'userNames' => $userNames,
]);
```

---

Requirements
------------

[](#requirements)

- **yiisoft/yii2**: ~2.0.14
- **cinghie/yii2-traits**: @dev

For timeline styling with AdminLTE 3:

- Module configured with `'bootstrap' => 'bootstrap4'`
- **cinghie/yii2-adminlte3** installed

---

Security and performance
------------------------

[](#security-and-performance)

See [SECURITY\_AND\_OPTIMIZATION.md](SECURITY_AND_OPTIMIZATION.md) for details on parameter validation, query limits, and Timeline widget usage.

---

License
-------

[](#license)

BSD-3-Clause

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance54

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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/cfedb99c8fcbaf668c4f9779d341997b84029673eda224241b11732981cbc8b2?d=identicon)[cinghie](/maintainers/cinghie)

---

Top Contributors

[![cinghie](https://avatars.githubusercontent.com/u/2445152?v=4)](https://github.com/cinghie "cinghie (24 commits)")

### Embed Badge

![Health badge](/badges/cinghie-yii2-logger/health.svg)

```
[![Health](https://phpackages.com/badges/cinghie-yii2-logger/health.svg)](https://phpackages.com/packages/cinghie-yii2-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[ekino/newrelic-bundle

Integrate New Relic into Symfony2

28111.2M8](/packages/ekino-newrelic-bundle)

PHPackages © 2026

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