<?php

/*
Looger.php is included.
*/
require_once('log4php/Logger.php');
/*
This class is use to generate a log file.
*/
class Loggerimplementation extends Exception{
/*
 Member for logger Object.
*/
    private $loggerObj;

/*
 Member for caller class ie class called loggerImplementation class.
*/
    private $callerClass;
/*
Constructor intialize the member caller class.
Also configure it with config.xml.
*/
    public function __construct($ClassName) {
       $this->callerClass=$ClassName;
       if($this->callerClass==NULL)
            throw new NullValueException('Caller Class Value is NULL');

       $loggerConfig = 'log4php/xml/config.xml';
        Logger::configure($loggerConfig);

        $this->loggerObj = Logger::getLogger($this->callerClass);

        if($this->loggerObj==NULL)
            throw new NullValueException('Logger Object Created is NULL');
    }
/*
Constructor intialize the member caller class.
Also configure it with anotherconfig.xml. This constructor is used for warn,
fatal,error cases.
*/
    public function __constructlevel($ClassName,$isErrSet) {
       if($isErrSet)
        {
            $this->callerClass=ClassName;
            if($this->callerClass==NULL)
                throw new NullValueException('Caller Class Value is NULL');

            $loggerConfig = 'log4php/xml/config.xml';
            Logger::configure($loggerConfig);

            $this->loggerObj = Logger::getLogger($this->callerClass);
            if($this->loggerObj==NULL)
                throw new NullValueException('Logger Object Created is
NULL');
        }
        else
        {
            throw new UnexpectedValueException("isErrSet value is wrong");
            }
    }
/*
function used to generate log message. In this , level will be check as it
passed as parameter according to which a log file is generated.
*/
    public function logMessage($message,$level)
    {

        if($message=="null")
            throw new NullValueException("message cant be null");

        if($level!="INFO" && $level!="DEBUG" && $level!="WARN" &&
$level!="ERROR" && $level!="FATAL")
            throw new UnexpectedValueException("Invalid value of Log
Level");
        if($level=="DEBUG")
            $this->loggerObj->debug($message);
        else
            if($level=="INFO")
            $this->loggerObj->info($message);
        else
            if($level=="WARN")
            $this->loggerObj->warn($message);
        else
            if($level=="ERROR")
            $this->loggerObj->error($message);
        else
            if($level=="FATAL")
            $this->loggerObj->fatal($message);
    }
}


?>

this is my wrapper.


On Fri, Jun 10, 2011 at 4:35 PM, Christian Grobmeier <grobme...@gmail.com>wrote:

> Hi,
>
> can you show us the Logging code?
>
> Esspecially the Logger::getLogger code is of interest.
>
> Thanks
> Christian
>
> On Fri, Jun 10, 2011 at 12:53 PM, Mohit Srivastava
> <srivastavamohi...@gmail.com> wrote:
> > Hi all,
> >
> > I write a wrapper over log4php api named as loggerimplementation.php
> >
> > Now i faced a problem in log files. When i called a function for logging
> > defined in loggerimplementation.
> >
> > Log file generated as:
> >
> > 2011-06-10 10:49:17 [INFO] Log4phpTest: Hello (at
> > C:\xampp\htdocs\logger\Loggerimplementation.php line 74)
> > 2011-06-10 10:50:08 [INFO] Log4phpTest: Hello (at
> > C:\xampp\htdocs\logger\Loggerimplementation.php line 74)
> > 2011-06-10 11:04:01 [INFO] Log4phpTest: Hello (at
> > C:\xampp\htdocs\logger\Loggerimplementation.php line 78)
> >
> > Now , as you can see %F will always show wrapper file name coz it always
> > called from there. But I want real file name which one used this wrapper.
> >
> > So please suggest me the way for this.
> >
> > Or
> > tell me from where %F details i can get?
> >
> > Waiting for reply.
> >
> > --
> > Mohit
> >
>
>
>
> --
> http://www.grobmeier.de
>

Reply via email to