5 steps to make it works :)

1. Download log4php http://www.vxr.it/log4php/download.html

2. Extract and copy log4php directory into app/vendors

3. create a log4php config file  (I put it under app/vendors/log4php/
config/MyLogger.xml )

-----File Start [MyLogger.xml ]------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<log4php:configuration xmlns:log4php="http://www.vxr.it/log4php/";
threshold="all" debug="false">

    <appender name="log4php_debug" class="LoggerAppenderFile">
                <param name="file" value="${LOGS}log4php_debug.log" />
        <layout class="LoggerPatternLayout">
            <param name="conversionPattern" value="%d [%t] %-5p %c %m
%n" />
        </layout>
    </appender>


    <root>
        <level value="debug" />
        <appender_ref ref="log4php_debug" />
    </root>
</log4php:configuration>
-----File End------------------------


4. create a components - controllers/components/log.php
-----File Start [log.php.xml ]------------------------
<?php
define('LOG4PHP_CONFIGURATION',
'vendors'.DS.'log4php'.DS.'config'.DS.'MyLogger.xml');
vendor('log4php'.DS.'LoggerManager');

class LogComponent extends Object{

        var $controller;
        var $logger;

        /*
         * init logger object
         */
    function startup( &$controller ) {
                $this->controller = &$controller;
                $this->init();
    }

    /*
     * Init Log component
     */
    function init(){
        if ($this->logger == null){

                $prefix = '('. $_SERVER['QUERY_STRING'] .')';
                $this->logger =& LoggerManager::getLogger( $prefix );
        }
    }

    /*
     * Debug
     * @param String text
     */
    function debug($text){
        $this->init();
        $this->logger->debug($text);
    }

    /*
     * info
         * @param String text*
     */
    function info($text){
        $this->init();
        $this->logger->info($text);
    }

    /*
     * warn
     * @param String text
     */
    function warn($text){
        $this->init();
        $this->logger->warn($text);
    }

    /*
     * error
     * @param String text
     */
        function error($text){
                $this->init();
        $this->logger->error($text);
    }

    /*
     * fatal
     * @param String text
     */
    function fatal($text){
        $this->init();
        $this->logger->fatal($text);
    }

    /*
     * Shutdown
     */
    function shutdown(){
        LoggerManager::shutdown();
    }
}
?>
-----File End------------------------

5. How-to use ?
in controller , add
var $components = array('Log');

function xxx (){
$this->Log->debug('DEBUG');
$this->Log->info('INFO');
$this->Log->warn('WARN');
$this->Log->error('ERROR');
$this->Log->fatal('FATAL');
}

~END~

Hope this can help.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to