vagrus/monolog-yii-ar-handler

A Monolog handler for send logs in Yii Active Record model

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

This package is auto-updated.

Last update: 2024-10-29 04:53:00 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);