You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jason Novotny <jd...@lbl.gov> on 2002/08/29 16:02:50 UTC

wrapping logger object

Hi,

    I'm trying to wrap the Logger object in Log4J into a proxy object, 
call it PortletLog

So a client that wants to log would do something like this:

PortletLog log = PortletLog.getInstance(MyClass.class);

// log using same interface as Logger
log.log("blah blah");

The PortletLog class looks like this:

class PortletLog {

    // must maintain a logger for each class in a hash or something
    private static Map logMap = new Hashtable();
    private Logger logger;

    PortletLog getInstance(Clazz clazz) {
        Logger log = (Logger)logMap.get(clazz);
        if (log != null) return log;
        log = Logger.getLogger(clazz);
        logMap.put(clazz, new SportletLog(clazz));
        return log;
    }

    public void log(String msg) {
          logger.log(msg);
    }     
..

}

    So I use the portletLog to maintain as many instance of Logger 
objects as there are unique classes that wish to log. This worked fine 
until we added config information in "%F %L" in the log4j.properties 
file to get the method name and line number of the logging class. Now, 
for that data, it always gives PortletLog line 86 which is where 
PortletLog is actually doing the logging.
Is there any way of forwarding this information to the proxy object as 
well, such that it will print out the original line number and method of 
the class that logs thru PortletLog?

    Thanks, Jason



 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: wrapping logger object

Posted by Ceki Gülcü <ce...@qos.ch>.
Have you read read the PatternLayout documentation? The conversion 
specifier you are looking for is %M.

At 17:16 29.08.2002 +0200, you wrote:

>    Hi,
>
>    Thanks for your quick response! Now I seem to get logging output like 
> this:
>
>34   [main] (GridSphere.java:68) INFO
>org.gridlab.gridsphere.portletcontainer.G
>ridSphere  - Apache Tomcat/4.0.323
>
>How do I get the actual method fo the class instead of [main]?? Is this 
>something in my properties file, or do  I need another library call?
>
>    Thanks, Jason
>
>Ceki Gülcü wrote:
>
>>
>>
>>
>>class PortletLog {
>>    ...
>>    Logger logger;
>>
>>    public void debug(String msg) {
>>          logger.log("package.name.PortletLog.", Level.DEBUG, msg, null);
>>    }
>>
>>See javadocs for the method log(String callerFQCN, Priority level,
>>Object message, Throwable t) in the org.apache.log4j.Category class.
>>
>>
>>At 16:02 29.08.2002 +0200, you wrote:
>>
>>>Hi,
>>>
>>>    I'm trying to wrap the Logger object in Log4J into a proxy object, 
>>> call it PortletLog
>>>
>>>So a client that wants to log would do something like this:
>>>
>>>PortletLog log = PortletLog.getInstance(MyClass.class);
>>>
>>>// log using same interface as Logger
>>>log.log("blah blah");
>>>
>>>The PortletLog class looks like this:
>>>
>>>class PortletLog {
>>>
>>>    // must maintain a logger for each class in a hash or something
>>>    private static Map logMap = new Hashtable();
>>>    private Logger logger;
>>>
>>>    PortletLog getInstance(Clazz clazz) {
>>>        Logger log = (Logger)logMap.get(clazz);
>>>        if (log != null) return log;
>>>        log = Logger.getLogger(clazz);
>>>        logMap.put(clazz, new SportletLog(clazz));
>>>        return log;
>>>    }
>>>
>>>    public void log(String msg) {
>>>          logger.log(msg);
>>>    }
>>>..
>>>
>>>}
>>>
>>>    So I use the portletLog to maintain as many instance of Logger 
>>> objects as there are unique classes that wish to log. This worked fine 
>>> until we added config information in "%F %L" in the log4j.properties 
>>> file to get the method name and line number of the logging class. Now, 
>>> for that data, it always gives PortletLog line 86 which is where 
>>> PortletLog is actually doing the logging.
>>>Is there any way of forwarding this information to the proxy object as 
>>>well, such that it will print out the original line number and method of 
>>>the class that logs thru PortletLog?
>>>
>>>    Thanks, Jason
>>>
>>>
>>>
>>>
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:
>>><ma...@jakarta.apache.org>
>>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>--
>>Ceki
>>
>>
>>--
>>To unsubscribe, e-mail:
>><ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>

--
Ceki


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: wrapping logger object

Posted by Jason Novotny <jd...@lbl.gov>.
    Hi,

    Thanks for your quick response! Now I seem to get logging output 
like this:

34   [main] (GridSphere.java:68) INFO  
org.gridlab.gridsphere.portletcontainer.G
ridSphere  - Apache Tomcat/4.0.323

How do I get the actual method fo the class instead of [main]?? Is this 
something in my properties file, or do  I need another library call?

    Thanks, Jason

Ceki Gülcü wrote:

>
>
>
> class PortletLog {
>    ...
>    Logger logger;
>
>    public void debug(String msg) {
>          logger.log("package.name.PortletLog.", Level.DEBUG, msg, null);
>    }
>
> See javadocs for the method log(String callerFQCN, Priority level,
> Object message, Throwable t) in the org.apache.log4j.Category class.
>
>
> At 16:02 29.08.2002 +0200, you wrote:
>
>> Hi,
>>
>>    I'm trying to wrap the Logger object in Log4J into a proxy object, 
>> call it PortletLog
>>
>> So a client that wants to log would do something like this:
>>
>> PortletLog log = PortletLog.getInstance(MyClass.class);
>>
>> // log using same interface as Logger
>> log.log("blah blah");
>>
>> The PortletLog class looks like this:
>>
>> class PortletLog {
>>
>>    // must maintain a logger for each class in a hash or something
>>    private static Map logMap = new Hashtable();
>>    private Logger logger;
>>
>>    PortletLog getInstance(Clazz clazz) {
>>        Logger log = (Logger)logMap.get(clazz);
>>        if (log != null) return log;
>>        log = Logger.getLogger(clazz);
>>        logMap.put(clazz, new SportletLog(clazz));
>>        return log;
>>    }
>>
>>    public void log(String msg) {
>>          logger.log(msg);
>>    }
>> ..
>>
>> }
>>
>>    So I use the portletLog to maintain as many instance of Logger 
>> objects as there are unique classes that wish to log. This worked 
>> fine until we added config information in "%F %L" in the 
>> log4j.properties file to get the method name and line number of the 
>> logging class. Now, for that data, it always gives PortletLog line 86 
>> which is where PortletLog is actually doing the logging.
>> Is there any way of forwarding this information to the proxy object 
>> as well, such that it will print out the original line number and 
>> method of the class that logs thru PortletLog?
>>
>>    Thanks, Jason
>>
>>
>>
>>
>>
>>
>> --
>> To unsubscribe, e-mail:   
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail: 
>> <ma...@jakarta.apache.org>
>>
>
> --
> Ceki
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: wrapping logger object

Posted by Ceki Gülcü <ce...@qos.ch>.


class PortletLog {
    ...
    Logger logger;

    public void debug(String msg) {
          logger.log("package.name.PortletLog.", Level.DEBUG, msg, null);
    }

See javadocs for the method log(String callerFQCN, Priority level,
Object message, Throwable t) in the org.apache.log4j.Category class.


At 16:02 29.08.2002 +0200, you wrote:

>Hi,
>
>    I'm trying to wrap the Logger object in Log4J into a proxy object, 
> call it PortletLog
>
>So a client that wants to log would do something like this:
>
>PortletLog log = PortletLog.getInstance(MyClass.class);
>
>// log using same interface as Logger
>log.log("blah blah");
>
>The PortletLog class looks like this:
>
>class PortletLog {
>
>    // must maintain a logger for each class in a hash or something
>    private static Map logMap = new Hashtable();
>    private Logger logger;
>
>    PortletLog getInstance(Clazz clazz) {
>        Logger log = (Logger)logMap.get(clazz);
>        if (log != null) return log;
>        log = Logger.getLogger(clazz);
>        logMap.put(clazz, new SportletLog(clazz));
>        return log;
>    }
>
>    public void log(String msg) {
>          logger.log(msg);
>    }
>..
>
>}
>
>    So I use the portletLog to maintain as many instance of Logger objects 
> as there are unique classes that wish to log. This worked fine until we 
> added config information in "%F %L" in the log4j.properties file to get 
> the method name and line number of the logging class. Now, for that data, 
> it always gives PortletLog line 86 which is where PortletLog is actually 
> doing the logging.
>Is there any way of forwarding this information to the proxy object as 
>well, such that it will print out the original line number and method of 
>the class that logs thru PortletLog?
>
>    Thanks, Jason
>
>
>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>

--
Ceki


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>