[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-user
Subject:    Re: wrapping logger object
From:       Ceki =?iso-8859-1?Q?G=FClc=FC?= <ceki () qos ! ch>
Date:       2002-08-29 15:23:20
[Download RAW message or body]


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:
>>><mailto:log4j-user-unsubscribe@jakarta.apache.org>
>>>For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>
>>
>>--
>>Ceki
>>
>>
>>--
>>To unsubscribe, e-mail:
>><mailto:log4j-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>
>>
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>
>

--
Ceki


--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic