92 log4j Logging

download link

 https://files-cdn.cnblogs.com/files/Scorpicat/log4j-1.2.12.jar.zip

Import Profiles

Found in the eclipse directory:

Under log4j.properties file into the project src

 

 

log4j import project

 

 Detailed configuration

 

Line 1: Global: INFO log level represents the lowest start as INFO, CONSOLE logging of execution to the console, if you want to output to a file, add: LOGFILE

Line 6: Customize a class trigger level

9-12: Output to the Console

Line 15-20: Export to profile

  • Line 16: the file path and file name, you can make an absolute path
  • Line 17: You can append
  • Line 20: output format

use

Level (highest to lowest):

  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG

 In correspondence with the place:

  • Usually FATAT and ERROR level used in the catch
  • As necessary with other
class the Test {public 
	public static void main (String [] args) { 
		Logger Logger = LogManager.getLogger (Test.class); 
		logger.fatal ( "I'm a fatal error message"); 
		logger.error ( "I was the error message" ); 
		logger.warn ( "I am warning message"); 
		logger.info ( "I'm info information"); 
		logger.debug ( "I am the debug information"); 
	} 
}

  

Error:

I can not solve fault

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Logger cannot be resolved to a type
Logger cannot be resolved

at com.xiaohei.test.Test.main(Test.java:7)

Guess you like

Origin www.cnblogs.com/Scorpicat/p/12325481.html