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 "Sira, Amardeep" <am...@etrade.com> on 2012/07/05 23:15:32 UTC

Alternative API for Category.log()

Hi,

Given that the Category and Priority classes are now deprecated, I am looking for an alternative API for "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable)<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(java.lang.String,%20org.apache.log4j.Priority,%20java.lang.Object,%20java.lang.Throwable)>".

My usecase consists of the logging being done by a generic helper class. Because of this, the method name printed in the log file is always that of the wrapper method of this helper class. The above log() API allows me to pass in the name of the helper class so that the resulting log prints the name of the actual calling method - as required.

Ex, MyClass.myMethod() needs to log a debug message. It calls MyHelper.debugWrapper(). The resulting log entry will look like,
DEBUG [Thread-Name] mypkg.MyClass.debugWrapper(): my message string
If, within MyHelper.debugWrapper(), instead of calling logger.debug(), I call log(mypkg.MyHelper, Priority.DEBUG, myMessage, null), the resulting log entry is,
DEBUG [Thread-Name] mypkg.MyClass.myMethod(): my message string

Kindly assist.

Thanks.

Amardeep


Re: Alternative API for Category.log()

Posted by Jacob Kjome <ho...@visi.com>.
If you are worried about said method being removed, don't worry.  But you 
should reference it via the Logger class.  Logger and Level replace Category 
and Priority.  But even if you were to reference it with the deprecated 
classes, you'll have no problems.  They will never be removed as Log4j-1.2.x 
won't ever be significantly changed.  Only bugfixes and maybe minor features 
will be applied.

All new development is occurring in the Log4j2 [2] codebase, but it's still in 
alpha for now.

[2] http://loggingtest.apache.org/log4j/2.x/


Jake

On Thu, 5 Jul 2012 21:15:32 +0000
 "Sira, Amardeep" <am...@etrade.com> wrote:
> Hi,
> 
> Given that the Category and Priority classes are now deprecated, I am 
>looking for an alternative API for 
>"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(java.lang.String, 
>org.apache.log4j.Priority, java.lang.Object, 
>java.lang.Throwable)<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(java.lang.String,%20org.apache.log4j.Priority,%20java.lang.Object,%20java.lang.Throwable)>".
> 
> My usecase consists of the logging being done by a generic helper class. 
>Because of this, the method name printed in the log file is always that of 
>the wrapper method of this helper class. The above log() API allows me to 
>pass in the name of the helper class so that the resulting log prints the 
>name of the actual calling method - as required.
> 
> Ex, MyClass.myMethod() needs to log a debug message. It calls 
>MyHelper.debugWrapper(). The resulting log entry will look like,
> DEBUG [Thread-Name] mypkg.MyClass.debugWrapper(): my message string
> If, within MyHelper.debugWrapper(), instead of calling logger.debug(), I 
>call log(mypkg.MyHelper, Priority.DEBUG, myMessage, null), the resulting log 
>entry is,
> DEBUG [Thread-Name] mypkg.MyClass.myMethod(): my message string
> 
> Kindly assist.
> 
> Thanks.
> 
> Amardeep
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org