How to add Log4j properties file in Java project
1 What is Log4j
2 How to implement Log4j in Java Project
What is Log4j
Log4j is a java based logging framework
Is simple, flexible, reliable and fast
Is configured through a configuration file
Log4j.xml OR log4j.properties etc...
Practical Example
Step 1:Add Log4j libraries in the java project
Can add jar files or maven dependency
[ Ссылка ]
Step 2 : Create reference for Logger in the class
Class where you want to add log statements
Step 3 : Create log4j.xml or log4j.properties file
Step 4 : Run and Validate
Log4j - log levels
TRACE
Most detailed information. Expect these to be written to logs only. Since version 1.2.12
DEBUG
Detailed information on the flow through the system. Expect these to be written to logs only. Generally speaking, most lines logged by your application should be written as DEBUG
INFO
Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum.
WARN
Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console.
ERROR
Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console.
FATAL
Severe errors that cause premature termination. Expect these to be immediately visible on a status console.
OFF
The highest possible rank and is intended to turn off logging
[ Ссылка ]
#name=PropertiesConfig
property.filename = logs
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/Mylogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers=file
logger.file.name=com.testng.utill
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
Ещё видео!