Is there any way to tell to log4j to write its log to the file and to the console?

in #java4 years ago (edited)

Your log4j File should look something like below read comments.

Define the types of logger and level of logging

log4j.rootLogger = DEBUG,console, FILE

Define the File appender

log4j.appender.FILE=org.apache.log4j.FileAppender

Define Console Appender

log4j.appender.console=org.apache.log4j.ConsoleAppender

Define the layout for console appender. If you do not

define it, you will get an error

log4j.appender.console.layout=org.apache.log4j.PatternLayout

Set the name of the file

log4j.appender.FILE.File=log.out

Set the immediate flush to true (default)

log4j.appender.FILE.ImmediateFlush=true

Set the threshold to debug mode

log4j.appender.FILE.Threshold=debug

Set the append to false, overwrite

log4j.appender.FILE.Append=false

Define the layout for file appender

log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

Coin Marketplace

STEEM 0.24
TRX 0.25
JST 0.040
BTC 93819.40
ETH 3392.19
USDT 1.00
SBD 3.40