vagrus/monolog-yii-ar-handler

A Monolog handler for send logs in Yii Active Record model

Installs: 3 749

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/vagrus/monolog-yii-ar-handler

v1.0 2015-12-05 21:29 UTC

This package is auto-updated.

Last update: 2025-10-29 01:51:01 UTC


README

These handler make it easy to send logs to Yii AR model.

Installation

Install the latest version with

$ composer require vagrus/monolog-yii-ar-handler

Basic Usage

<?php

use Monolog\Logger;
use Vagrus\Monolog\Handler\YiiArHandler;

$mappingSettings = array(
    '*' => 'modelProperty', // required
);

// create a log channel
$log = new Logger('name');
$log->pushHandler(new YiiArHandler('modelName', $mappingSettings, Logger::WARNING));

// add records to the log
$log->warning('Foo');

Extended Usage

<?php

use Monolog\Logger;
use Vagrus\Monolog\Handler\YiiArHandler;

$mappingSettings = array(
    '*' => 'property1', // required
    'contextVar1' => 'property2',
    'contextVar2' => 'property3',
);

// create a log channel
$log = new Logger('name');
$log->pushHandler(new YiiArHandler('modelName', $mappingSettings, Logger::WARNING));

// add records to the log
// 'Foo' will be written to model's property1, 'some context value' to property2, etc. 
$context = array(
    'contextVar1' => 'some context value',
    'contextVar2' => 'other context value',
);
$log->warning('Foo', $context);