1

I am writing a Java application in IntelliJ and I am using log4j. I disabled the console output from the xml file, but it keeps outputting when I run the jar (not the java, the JAR). I use this repository for some experiments: https://github.com/optimaize/language-detector

I have already tried to add log4j.properties and different configurations of log4j.xml, but it keeps outputting the console information. This one is my log4j.xml file located at: src/main/resources/log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="file" class="org.apache.log4j.RollingFileAppender">
  <param name="append" value="false" />
  <param name="maxFileSize" value="10MB" />
  <param name="maxBackupIndex" value="10" />
  <param name="file" value="C:/logs/myStruts1App.log" />
</appender>

<root>

 <level value="INFO" />
    <appender-ref ref="file" />
</root>

</log4j:configuration>

According to other guides here on stack overflow, this should make it. But when I run the jar: java -jar MyJar.jar it outputs

17:20:41.017 [main] DEBUG c.o.langdetect.LanguageDetectorImpl - ==> [DetectedLanguage[bn:0.9999940935958097]]
17:20:41.019 [main] DEBUG c.o.langdetect.LanguageDetectorImpl - ==> [DetectedLanguage[bn:0.9999940935958097]]
17:20:41.020 [main] DEBUG c.o.langdetect.LanguageDetectorImpl - ==> [DetectedLanguage[en:0.9999940935958097]]
17:20:41.020 [main] DEBUG c.o.langdetect.LanguageDetectorImpl - ==> [DetectedLanguage[fr:0.9999940935958097]] ...
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
Mazzespazze
  • 111
  • 12

1 Answers1

0

This answer has the working example.

If you remove stdout, from log4j.rootLogger=INFO, stdout, file line in HelloWithDependencies\resources\log4j.properties file and rebuild the .jar artifact, it will not produce any console output, the logging will go into the file only.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • This is my log4j.properties and it still console outputs: # Define the root logger with appender file log4j.rootLogger = info, FILE # Define the file appender log4j.appender.FILE=org.apache.log4j.FileAppender log4j.appender.FILE.File=${log}/log.out # Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%m%n – Mazzespazze Apr 03 '19 at 08:20
  • @Mazzespazze please download the example and see how the project is configured. – CrazyCoder Apr 03 '19 at 08:33