Linux big data project can not output log file solution

There is no error in the code when outputting log information in Hadoop, but the log file cannot be viewed.

The reason for this problem is that the program refers to other jar packages during execution, and the referenced jar packages may contain other log4j related configuration files. Due to the priority of the log4j configuration file reference, the program did not use the log4j.properties file we changed earlier, but used the configuration file in the jar package, resulting in the change did not work.

The solution is to directly specify the log4j.properties file used by adding code in the class where the main method is located:

  • First put the log4j.properties file in the Linux specified directory, such as / usr / local / test /
  • Second, import the relevant packages:
import org.apache.log4j.PropertyConfigurator
  • Add a statement at the end:
PropertyConfigurator.configure("/usr/local/test/log4j.properties")
Published 460 original articles · praised 812 · 90,000 views

Guess you like

Origin blog.csdn.net/lianghecai52171314/article/details/105578020