0

Trying to use log4j and the java utility logging in a single application but on different classes but log4j stops logging once I configure util logging on another class.

I am loading the properties file for the util logging whereas the xml file is for log4j config is in the classpath.

How can I configure both?

Dheeraj
  • 233
  • 1
  • 5
  • 14
  • It is definitively be possible to do both. You should add how you configure your logging to the question. Do you use code, xml or .properties? And how is your configuration loaded? – Mathjoh Dec 08 '17 at 09:16
  • @Mathjoh: I've added a little more detail now. – Dheeraj Dec 08 '17 at 09:34
  • It's possible, but stupid. Interestingly enough, using `java.util.logging` itself is quite stupid, so unless you're forced for some unknown reason to use it, don't. – Kayaman Dec 08 '17 at 09:46
  • @Kayaman: Yes, it is forced as it is considered a standard for logging application logs in my project. – Dheeraj Dec 08 '17 at 10:30
  • You might want to reconsider your standards. See for example https://stackoverflow.com/questions/11359187/why-not-use-java-util-logging – Kayaman Dec 08 '17 at 10:52
  • @Dheeraj As the different logging classes have their own configuration they should be able to feed their logs to the same output. So unless you overwrite come config for when when you do the other it should work right out the box. If the problem is configuring util logging after log4j, have you tried change the order in which you load the configs? – Mathjoh Dec 08 '17 at 10:53
  • 1
    Provide a minimal code/configuration example that others can run to reproduce your problem. – tkruse Dec 09 '17 at 16:03
  • 1
    @Kayaman Using java.util.logging is not stupid and the link you refer to in support of not using it is now quite out of date. Java util logging has come a long way recently with the addition of new Java 8 features which means that it now performs very well. – DodgyCodeException Dec 15 '17 at 16:44
  • @DodgyCodeException it has never been about performance but the design flaws in it. An experienced developer would never use `java.util.logging`. – Kayaman Dec 17 '17 at 12:27
  • @Kayaman sorry, I disagree. In my experience, I've seen many experienced developers use java.util.logging. Firstly because, when you create a Java application for an end-user, you don't have to supply additional dependent jars. Secondly because later releases of java.util.logging have a nicer API than, for example, slf4j (using printf-like parameter syntax rather than the unintuitive and inflexible "{}"). – DodgyCodeException Dec 17 '17 at 13:24

0 Answers0