Git Product home page Git Product logo

yii2-logger's Introduction

Yii2 Custom Logger

Sending Yii2 application logs to different targets asynchronously or synchronously.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist apollo11/yii2-logger "~1.0"

or add

"apollo11/yii2-logger": "~1.0"

to the require section of your composer.json file.

The package offers:

  1. Abstract Target class with support of sending messages asynchronously. It also has possibility to hide sensitive information when sending $_POST or other $GLOBALS data to target.
  2. Slack target: Sending messages to slack channel

Basic Usage

The package supports three target classes: EmailTarget, SlackTarget, DbTarget.

All target classes have support for sending messages asynchronously and hide passwords(or other sensitive data) provided by user. If you set async to true than you must provide the consoleAppPath.

EmailTarget and DbTarget work pretty much in the simillar way as it is described in Yii Documentation.

Add the following code to your project configuration file under components -> log -> targets

'class' => <Target class>,
// If async is set to true you have to provide consoleAppPath
'async' => true,
'consoleAppPath' => Yii::getAlias('@console/yii'),
// If you would like to use different php binary, when sending messages asynchronously you can set it from here
// 'phpExecPath' => 'php',
// Provide here keys which will be hidden before sending messages. It is case insensitive
'excludeKeys' => [
    '*PASSWORD*', // Will hide all keys from $GLOBALS objects which contains "password".
    '*PASSWORD', // Will hide all keys from $GLOBALS objects which ends with "password".
    'PASSWORD*', // Will hide all keys from $GLOBALS objects which starts with "password".
],

SlackTarget

'class' => apollo11\logger\SlackTarget::class,
'except' => ['yii\web\HttpException:*', 'yii\web\HeadersAlreadySentException'],
'webhookUrl' => <Slack channel webhook url>,
'icon_url' => '<Slack sender icon url>',
'icon_emoji' => '<Slack sender icon emoji>', // If both, icon_url and icon_emoji is provided system will use icon_emoji
'levels' => ['error', 'warning'],
'title_link' => '<Url which will be opened when clicking on title of the slack message>',
'async' => true,
'consoleAppPath' => Yii::getAlias('@console/yii'),
'username' => '<Username which will be used as sender on slack channer>',
'excludeKeys' => [],

Important

If you set async property to true, you must add the following code into your console application controllerMap

'async' => [
    'class' => \apollo11\logger\AsyncController::class,
],

yii2-logger's People

Contributors

zura024 avatar thecodeholic avatar paskuale75 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.