Results 1 to 5 of 5
  1. #1
    jakSun8 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default 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?

  3. #3
    jakSun8 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default 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

  4. #4
    jakSun8 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default 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

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default 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

  1. Replies: 5
    Last Post: 03-17-2011, 02:26 PM
  2. log4j class logger disabling
    By lowlyintern in forum New To Java
    Replies: 1
    Last Post: 06-18-2010, 01:49 PM
  3. log4j class logger disabling
    By lowlyintern in forum Advanced Java
    Replies: 2
    Last Post: 06-17-2010, 02:51 PM
  4. Replies: 0
    Last Post: 05-19-2010, 09:44 PM
  5. Get the Line number in log with Log4j Logger.
    By Anny_1985 in forum Web Frameworks
    Replies: 0
    Last Post: 07-24-2009, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •