All Projects → merorafael → yii2-monolog

merorafael / yii2-monolog

Licence: MIT license
Yii 2 Monolog extension

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-monolog

Yii2 File Upload Widget
BlueImp File Upload Widget for Yii2
Stars: ✭ 251 (+543.59%)
Mutual labels:  yii
monolog-google-cloud-json-formatter
A Monolog extension for formatting log entries for Google Cloud Logging
Stars: ✭ 15 (-61.54%)
Mutual labels:  monolog
Monolog Bridge
Provides integration for Monolog with various Symfony components.
Stars: ✭ 2,238 (+5638.46%)
Mutual labels:  monolog
monolog-gdpr
Some Monolog processors that help with GDPR compliance
Stars: ✭ 49 (+25.64%)
Mutual labels:  monolog
codeigniter-monolog-plus
codeigniter monolog plus
Stars: ✭ 13 (-66.67%)
Mutual labels:  monolog
monolog-sentry-handler
Monolog handler for Sentry PHP SDK v2 with breadcrumbs support
Stars: ✭ 34 (-12.82%)
Mutual labels:  monolog
Yii2 Framework
[READ ONLY] Yii 2 framework core code only. This is a subtree split off the "yii2" repository
Stars: ✭ 221 (+466.67%)
Mutual labels:  yii
install
basic script for project installation
Stars: ✭ 17 (-56.41%)
Mutual labels:  yii
app
Buggregator is a beautiful, lightweight debug server build on Laravel that helps you catch your smpt, sentry, var-dump, monolog, ray outputs. It runs without installation on multiple platforms.
Stars: ✭ 259 (+564.1%)
Mutual labels:  monolog
logger
A Monolog-based logging tool for WordPress. Supports storing log message in a custom post type or in individual posts and terms.
Stars: ✭ 20 (-48.72%)
Mutual labels:  monolog
slim-skeleton
Slim Framework skeleton application following MVC construction
Stars: ✭ 18 (-53.85%)
Mutual labels:  monolog
monolog-telegram-handler
Monolog handler to send log by Telegram
Stars: ✭ 32 (-17.95%)
Mutual labels:  monolog
monolog-http
A collection of monolog handlers that use a PSR-18 HTTP Client to send your logs
Stars: ✭ 34 (-12.82%)
Mutual labels:  monolog
Yiiframework.com
Source code for official Yii website
Stars: ✭ 252 (+546.15%)
Mutual labels:  yii
Easy Log Handler
Human-friendly log files that make you more productive
Stars: ✭ 2,070 (+5207.69%)
Mutual labels:  monolog
Yii2 Apidoc
Yii 2 apidoc extension.
Stars: ✭ 236 (+505.13%)
Mutual labels:  yii
REST-Api-with-Slim-PHP
REST API with PHP Slim Framework 3 and MySQL
Stars: ✭ 69 (+76.92%)
Mutual labels:  monolog
yii2-admin-theme
基于Yii2+layui的后台框架模板,实现了完善的RBAC权限控制
Stars: ✭ 87 (+123.08%)
Mutual labels:  yii
Monolog Bundle
Symfony Monolog Bundle
Stars: ✭ 2,532 (+6392.31%)
Mutual labels:  monolog
enlite-monolog
Monolog integration to Laminas
Stars: ✭ 17 (-56.41%)
Mutual labels:  monolog

Monolog for Yii 2

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License

The Monolog integration for the Yii framework.

Requirements

  • PHP 5.4 or above
  • Yii 2.0.0 or above

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/yii2-monolog to add Monolog in your project vendor.

Configuration

To configure Monolog component in Yii2, use the structure exemplified below. The channel "main" is required in component and used when no channel is setted to use a logger.

return [
    //....
    'components' => [
        'monolog' => [
            'class' => '\Mero\Monolog\MonologComponent',
            'channels' => [
                'main' => [
                    'handler' => [
                        //Handler object or array configuration
                    ],
                    'processor' => [],
                ],
            ],
        ],
    ],
    //....
];

You can configure multiple channels and different handlers and processors for each channel.

Example

return [
    //...
        'channels' => [
            'main' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/main_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
            'channel1' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/channel1_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
            'channel2' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/channel1_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
        ],
    //...
];

Handlers

You can add handlers in their channels using the array structure or object structure.

Array structure

Using the array structure, you have a better readability of the configuration of their handlers.

Example

return [
    //...
    'handler' => [
        [
            'type' => 'stream',
            'path' => '@app/runtime/logs/log_' . date('Y-m-d') . '.log',
            'level' => 'debug'
        ]
    ],
    //...
];

Warning: this option does not have any existing handlers in monolog. See the handlers page more details.

Object structure

Using the object structure, you will be informing instantiated objects already declared their respective handlers.

Example

return [
    //...
    'handler' => [
        new \Monolog\Handler\StreamHandler(
            __DIR__.'/../runtime/logs/system.log',
            \Monolog\Logger::DEBUG
        )
    ],
    //...
];

Using Yii2 Monolog

To use Yii 2 Monolog simply call the method getLogger component informing which channel is used.

Example

namespace app\controllers;

use Yii;
use \yii\web\Controller;

class ExampleController extends Controller
{

    /**
     * This action register "Hello world" in channel 
     * "main"(default when no value is setted on "getLogger" method).
     */
    public function actionFirstExample()
    {
        $monologComponent = Yii::$app->monolog;
        $logger = $monologComponent->getLogger();
        $logger->log('info', 'Hello world');
    }

    /**
     * This action register "Hello world" in channel "channel1".
     */
    public function actionSecondExample()
    {
        $monologComponent = Yii::$app->monolog;
        $logger = $monologComponent->getLogger("channel1");
        $logger->log('info', 'Hello world');
    }
    
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].