File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple log4j configurations in a single classloader ?

 
Dev Das
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a requirement where in I want to use log4j logging for a single component(read java class) in my application, but the problem is that a log4j configuration is already in place for other third party components in the same classloader scope. I tried configuring the log4j properties programmatically. It logs fine for the target log file, which I had set for the my appender, for sometime, but later on the logs get printed in the file specified by the root logger appender(which is specified in the core log4j.properties). How can I circumvent the situation? Any suggestions ?

I forgot mentioning that once the logs get printed in the root appender file, they no longer get printed to the file appender which I have set.

TIA
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you setting the log4j properties programmatically? Do you have access to the actual log4j.properties or log4j.xml?
 
Dev Das
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijn,

It's like this:
logger = Logger.getLogger (Myclass.class);
l_log_path = "FILE_PATH"
l_layout = new PatternLayout (PRINT_PATTERN);
l_dailyfile_appender = new DailyRollingFileAppender (
l_layout
, l_log_path + "/"+ DEFAULT_LOG_FILE
, "'.'yyyy-MM-dd"
);
logger.addAppender (l_dailyfile_appender);
logger.setLevel (Level.AL

Is there any issue in the same ?
 
Dev Das
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, It's something like this:


logger = Logger.getLogger (THIS_COMPONENT_NAME);
l_log_path = LOG_PATH;
l_layout = new PatternLayout (PRINT_PATTERN);
l_dailyfile_appender = new DailyRollingFileAppender (
l_layout
, l_log_path + "/"+ DEFAULT_LOG_FILE
, "'.'yyyy-MM-dd"
);
logger.addAppender (l_dailyfile_appender);
logger.setLevel (Level.ALL);

Is there any issue in the same ?
 
Dev Das
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have used the addAppender, setLevel methods on the logger instance which I retrieved using Logger.getLogger(Myclass.class). I know it's not the
recommended way. But i think it works.

TIA
- DD
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert on configuring it in Java code, but it looks like that should work yes. Can you not actually access the properties file itself?
 
Dev Das
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The main configuration file is for a different module altogether. It's just that their jar files are exposed to our application because we refer them. Since there is a shared class loader for all the jars, I can not configure my separate log4j configuration. In case I define a root logger in my own config file, it may overwrite theirs and that won't be a welcome situation.

So I was just trying to devise a way and hence I posted this query. It seems now that I'll have to append my configuration in their properties file only.


Thanks..
Dev Das
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic