Git Product home page Git Product logo

magemonolog's Introduction

magemonolog

Facts

Version: 0.2.2 Developed (and tested) on Magento CE v 1.8.1.0

Introduction

A Magento extension which provides a custom writer model to transparently use Monolog as logging library.

The following Monolog's Handlers are supported at the moment:

  • StreamHandler - writes to file
  • NativeMailHandler - sends each log entry via email
  • NewRelicHandler - logs in NewRelic app

Installation

You can install this extension in several ways:

Download

Download the full package, copy the content of the app directory in your Magento base directory; pay attention not to overwrite the app folder, only merge its contents into existing directory;

Modman

Install modman Module Manager: https://github.com/colinmollenhour/modman

After having installed modman on your system, you can clone this module on your Magento base directory by typing the following command:

$ modman init
$ modman clone [email protected]:aleron75/magemonolog.git

Composer

Install composer: http://getcomposer.org/download/

Install Magento Composer: https://github.com/magento-hackathon/magento-composer-installer

Type the following command:

$ php composer.phar require aleron75/magemonolog:dev-master

or

$ composer require aleron75/magemonolog:dev-master

Common tasks

After installation:

  • if you have cache enabled, disable or refresh it;
  • if you have compilation enabled, disable it or recompile the code base.

Usage example

Once installed, the module automatically replaces the default Magento Log Writer with Monolog's StreamHandler.

This is obtained through the following config node in config.xml:

<config>
    <global>
        <log>
            <core>
                <writer_model>Aleron75_Magemonolog_Model_Logwriter</writer_model>
            </core>
        </log>
    </global>
</config>

which instructs Magento to use a custom log writer class when logging via the Mage::log() native static function.

The configured Aleron75_Magemonolog_Model_Logwriter class is a wrapper for Monolog and allows to use Monolog's Handlers.

Monolog's Handlers are configured in the config.xml through the following config node:

<config>
    <default>
        <magemonolog>
            <handlers>
                <StreamHandler>
                    <active>1</active>
                    <params>
                        <stream>magemonolog.log</stream>
                        <level>DEBUG</level>
                        <bubble>true</bubble>
                        <filePermission>null</filePermission>
                        <useLocking>false</useLocking>
                    </params>
                </StreamHandler>
                <NativeMailHandler>
                    <active>0</active>
                    <params>
                        <to>[email protected]</to>
                        <subject>Log</subject>
                        <from>[email protected]</from>
                        <level>ERROR</level>
                        <bubble>true</bubble>
                        <maxColumnWidth>70</maxColumnWidth>
                    </params>
                </NativeMailHandler>
                <NewRelicHandler>
                    <active>0</active>
                    <params>
                        <level>ERROR</level>
                        <bubble>true</bubble>
                        <appname>***your app name here***</appname>
                    </params>
                </NewRelicHandler>
            </handlers>
        </magemonolog>
    </default>
</config>

It is assumed you know Monolog's Handlers to understand the meaning of params node.

Multiple Log Handlers can be activated at the same time with different log filter level; this way, for example, it is possible to log any message into a file and only serious errors via e-mail.

You can also use Monolog's Formatters like shown below:

<config>
    <default>
        <magemonolog>
            <handlers>
                <StreamHandler>
                    <active>1</active>
                    <params>
                        <stream>magemonolog.log</stream>
                        <level>DEBUG</level>
                        <bubble>true</bubble>
                        <filePermission>null</filePermission>
                        <useLocking>false</useLocking>
                    </params>
                    <formatter>
                        <class>LogstashFormatter</class>
                        <args>
                            <application_name><![CDATA[MyAppName]]></application_name>
                            <system_name><![CDATA[]]></system_name>
                            <extra_prefix><![CDATA[]]></extra_prefix>
                            <context_prefix><![CDATA[]]></context_prefix>
                            <version><![CDATA[]]></version>
                        </args>
                    </formatter>
                </StreamHandler>
            </handlers>
        </magemonolog>
    </default>
</config>

The <args> tag should contain proper Formatter's contructor arguments. Arguments' tag name is not important, values are passed to Formatter's constructor in the exact order the constructor requires them. You should consult Formatter's constructor signature to know which are its arguments, their meaning and their order.

Closing words

Any feedback is appreciated.

This extension is published under the Open Software License (OSL 3.0).

Any contribution or feedback is extremely appreciated.

magemonolog's People

Contributors

aleron75 avatar ddonnini 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.