本文共 3160 字,大约阅读时间需要 10 分钟。
log4j log4j 1.2.17
log=D:/log4jlog4j.rootCategory=INFO, stdout,filelog4j.rootLogger=INFO, stdout,file### stdout ###log4j.appender.stdout= org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %t %p %C.%M(%L) %m%nlog4j.org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager=INFOlog4j.org.apache.http.impl.nio=INFO# Define the file appenderlog4j.appender.file=org.apache.log4j.RollingFileAppender#log4j.appender.file.File=${log}/log.loglog4j.appender.file.File=./log.log# Define the layout for file appenderlog4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.conversionPattern=%d{HH:mm:ss} %t %p %C.%M(%L) %m%n# File max sizelog4j.appender.file.MaxFileSize=100MB# Keep three backup files.log4j.appender.file.MaxBackupIndex=3650
public class Log4jExample { public static void main(String[] args){ Logger log = Logger.getLogger( Log4jExample.class.getName()); log.debug("Hello this is an debug message"); log.info("Hello this is an info message"); }}
org.slf4j slf4j-api 1.7.21 org.slf4j slf4j-log4j12 1.7.21
public class Slf4jExample { public static void main(String[] args) throws IOException,SQLException { Logger logger = LoggerFactory.getLogger(Slf4jExample.class); logger.info(">>>>>>{}","Hello this is an info message"); }}
org.projectlombok lombok 1.16.18 provided
@Slf4jpublic class LombokExample { public static void main(String[] args) { log.info(">>>>>>{}", "Hello this is an info message"); }}效果是一样的,我就不再展示了