Results 1 to 5 of 5
Thread: Log4j Logger question
- 03-24-2012, 02:05 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Log4j Logger question
Hi,
I have a question on the dilemma i have. I am using Logger in a lot of places in my code base. Currently the level is set via log4j properties files. This require re-comiple every time i change the level. I am thinking to have a command-line variable which will store the level value. I then read that variable and call setLevel(). But this also requires reading/setting in several places.
So, i was thinking if i could create my own subclass MyLogger which will inherit from Logger that will take level from the constructor and somehow that will setLevel
I need your help if you can provide me a sample snippet on how this could be achieved or if you have a better idea.
Thanks,
JaK
- 03-24-2012, 04:26 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,638
- Rep Power
- 13
Re: Log4j Logger question
I don't understand why you need to recompile every time you change if you have your preferences in a properties file. That is one of the points of having them set within a file - so that file may be stored external to the application. Are you packaging this file inside a jar? If so, is there anything from preventing you from storing this outside the jar?
- 03-24-2012, 04:49 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Log4j Logger question
Thanks for the reply, doWhile! Yes log4j.properties file in packaged inside the jar. I am not sure why since i am new the team. Let me try to not include this file in the jar.
Thanks again,
JaK
- 03-24-2012, 05:51 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Log4j Logger question
If i remove log4j.properties from my jar file i am getting following error
log4j:ERROR setFile(null,true) call failed
- 03-24-2012, 08:41 PM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,638
- Rep Power
- 13
Re: Log4j Logger question
Did you change the file path to the properties file so it points to your new location? Using configuration files is all explained in the Log4j Manual and API: Apache log4j 1.2 - Short introduction to log4j
Similar Threads
-
java.lang.NoSuchMethodError: org.apache.log4j.Logger.log(Ljava/lang/String;Lorg/apach
By rameshraj in forum JDBCReplies: 5Last Post: 03-17-2011, 02:26 PM -
log4j class logger disabling
By lowlyintern in forum New To JavaReplies: 1Last Post: 06-18-2010, 01:49 PM -
log4j class logger disabling
By lowlyintern in forum Advanced JavaReplies: 2Last Post: 06-17-2010, 02:51 PM -
Programmatically configuring Log4J Logger while leaving config alone
By Hichhiker in forum Advanced JavaReplies: 0Last Post: 05-19-2010, 09:44 PM -
Get the Line number in log with Log4j Logger.
By Anny_1985 in forum Web FrameworksReplies: 0Last Post: 07-24-2009, 01:18 PM
Bookmarks