0

I'd like to programmatically adjust my logging file locations. Thus I want to overwrite the default values in my log4j.properties file. This is not opposing any problems I am using LogManager.resetConfiguration() and PropertyConfigurator.configure(props) so that my file locations are updated (stored in props). This methodology works, logging files are from this point onward written to a new file location.

My problem occurs when using Weld. This is due the fact that Weld internally is using a logger as well, stated in my logging-file: 2014-08-13 12:55:15.589 [main:0] DEBUG Weld.java:84 Method: <clinit> - Logging Provider: org.jboss.logging.Log4jLoggerProvider.

Since I'm using org.jboss.weld.environment.se.StartMain as main class, I do not have any influence on the logging capabilities of Weld. I now end up with 3 logging files (as described in my log4j.properties) on 2 different locations. Whereas one contains some Weld debug information and the other contains all the logging information from initialization and onward.

Thus logically I'd like to end up with only 1 directory with logging files, thus that Weld adjusts to the new log4j file location. Or to have log4j to copy the old logging contents, create new logging files + with old content and to delete the old logging files.

I do not want to use VM arguments, since I need to programmatically assign the logging locations.

Velth
  • 1,108
  • 3
  • 15
  • 29

1 Answers1

0

The solution in cases like this is to use slf4j. See bridging legacy apis.

Once you bridged all logging, you can use slf4j-to-log4j to direct all logging to your log4j settings.

Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
  • Thanks for the comment, I managed to load slf4j and slf4j-log4j12 and set the logging provider of weld to org.jboss.logging.Slf4jLoggerProvider. But still, weld is logging before I'm able to set my logging directories. Thus I still end up with 2 logging files (altho all logging after weld initialized is written to the new logging file). Any clue(s)? – Velth Aug 15 '14 at 08:33
  • Could you show me some code? Where do you init your loggers? – Jan Galinski Aug 15 '14 at 09:25