Download the PHP package praxigento/mage_ext_log4php without Composer

On this page you can find all versions of the php package praxigento/mage_ext_log4php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mage_ext_log4php

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:

Usage

Simple usage

Usage in case of your own module has dependency to Praxigento_Log:

$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):

<?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:

$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");

All versions of mage_ext_log4php with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package praxigento/mage_ext_log4php contains the following files

Loading the files please wait ....