标签:
Commons logging提供统一的log系统接入,基本的commons logging能实现console输出,当然commons logging也提供其它诸如log4j的接入
<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency>
基本输出规则: console输出。
package com.test; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Created by ygshen on 7/23/16. */ public class mainclass { // Logger factory 会查询logging的实现来定义具体的Log方式,如果没有定义诸如log4j的log 实现 那么 //logging使用的是默认的console 输出 private static Log logger= LogFactory.getLog(mainclass.class); public static void main(String[] args){ logger.info("test information"); logger.error("test error message"); } }
common logging 可以提供其它高级logging的基础支持。比如log4j
Logging4J+common-logging 使用方法:
<!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.6.2</version> </dependency>
commons-logging.properties
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
Log4J.properties: 这个配置文件 主要是用来配置Appender的即输出目标,主要包括 consoleAppender, FileAppender
#定义成默认的Console输出
log4j.rootLogger=debug,stdout ### 输出到控制台 ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out ## 输出INFO级别以上的日志 log4j.appender.stdout.Threshold=INFO log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Define the root logger with appender file log=/home/ygshen/WorkSpace/logs log4j.rootLogger =info,file ### 输出到日志文件 ### log4j.appender.file = org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File = ${log}/log.out log4j.appender.file.Append = true # Define the layout for file appender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.conversionPattern=%m%n
标签:
原文地址:http://www.cnblogs.com/ygshen/p/5699170.html