2017 © Pedro Peláez
 

magento-module mage_ext_log4php

Log4php wrapper to use Log4php with Magento

image

praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  • Thursday, March 31, 2016
  • by praxigento
  • Repository
  • 14 Watchers
  • 4 Stars
  • 315 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

Log4php wrapper to use Log4php with Magento

Installation

{
  "require": {
    "praxigento/mage_ext_log4php": "*"
  },
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/praxigento/mage_ext_log4php"
    }
  ]
}

Configuration

Go to System / Configuration / Developer / Log Settings and setup path to Log4php configuration file relative to the Magento root folder:, (*1)

Magento Configuration, (*2)

Usage

Simple usage

Usage in case of your own module has dependency to Praxigento_Log:, (*3)

$log       = Praxigento_Log_Logger::getLogger(__CLASS__);
$log->trace("trace level message");
$log->debug("debug level message");
$log->info("info level message");
$log->warn("warn level message");
$log->error("error level message");
$log->fatal("fatal level message");

Create adapter in your own module

Use adapter to automatically switch between Praxigento_Log wrapper (if installed) and Magento default logs (otherwise):, (*4)

<?php
class Namespace_Module_Logger
{
    /** @var bool 'true' - Log4php logging framework is used. */
    private static $_isLog4phpUsed = null;
    /** @var Praxigento_Log_Logger */
    private $_loggerLog4php;
    /** @var string name for the current logger */
    private $_name;

    function __construct($name)
    {
        /**
         * switch off/on error reporting to prevent messages like
         * "ERR (3): Warning: include(Praxigento\Log\Logger.php): failed to open stream: No such file or directory"
         * in case of Praxigento_Log module is not used. 
        */
        $level = error_reporting(0);
        self::$_isLog4phpUsed = class_exists('Praxigento_Log_Logger', true);
        error_reporting($level);
        if (self::$_isLog4phpUsed) {
            $this->_loggerLog4php = Praxigento_Log_Logger::getLogger($name);
        } else {
            $this->_name = is_object($name) ? get_class($name) : (string)$name;
        }
    }

    /**
     * Override getter to use '$log = Praxigento_Log_Logger::getLogger($this)' form in Mage classes.
     * @static
     *
     * @param string $name
     *
     * @return Namespace_Module_Logger
     */
    public static function getLogger($name)
    {
        $class = __CLASS__;
        return new $class($name);
    }

    public function debug($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'debug', Zend_Log::INFO);
    }

    public function error($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'error', Zend_Log::ERR);
    }

    public function fatal($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'fatal', Zend_Log::CRIT);
    }

    public function info($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'info', Zend_Log::NOTICE);
    }

    public function trace($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'trace', Zend_Log::DEBUG);
    }

    public function warn($message, $throwable = null)
    {
        $this->doLog($message, $throwable, 'warn', Zend_Log::WARN);
    }

    /**
     * Internal dispatcher for the called log method.
     * @param $message
     * @param $throwable
     * @param $log4phpMethod
     * @param $zendLevel
     */
    private function doLog($message, $throwable, $log4phpMethod, $zendLevel)
    {
        if (self::$_isLog4phpUsed) {
            $this->_loggerLog4php->$log4phpMethod($message, $throwable);
        } else {
            Mage::log($this->_name . ': ' . $message, $zendLevel);
            if ($throwable instanceof Exception) {
                Mage::logException($throwable);
            }
        }
    }
}

Use your own adapter to log messages:, (*5)

$log       = Namespace_Module_Logger::getLogger(__CLASS__);
$log->trace("Log your message with Log4php (in case of Praxigento_Log extension is installed) or with Magento log (otherwise)");
$log->debug("debug level message");
$log->info("info level message");
$log->warn("warn level message");
$log->error("error level message");
$log->fatal("fatal level message");

The Versions

31/03 2016

dev-master

9999999-dev https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

by Alex Gusev
by Vladimir Golobokov

25/06 2015

0.6.0

0.6.0.0 https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

by Alex Gusev
by Vladimir Golobokov

23/03 2015

v0.5.0

0.5.0.0 https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

by Alex Gusev
by Vladimir Golobokov

21/03 2015

dev-0.4.0-rc

dev-0.4.0-rc https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

The Requires

 

by Alex Gusev
by Vladimir Golobokov

04/03 2015

v0.4.0

0.4.0.0 https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

The Requires

 

by Alex Gusev
by Vladimir Golobokov

12/02 2015

dev-AD-41-vg

dev-AD-41-vg https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

The Requires

 

by Alex Gusev
by Vladimir Golobokov

30/01 2015

dev-AD-41

dev-AD-41 https://github.com/praxigento/mage_ext_log4php

Log4php wrapper to use Log4php with Magento

  Sources   Download

MIT

The Requires

 

by Alex Gusev