maven配置简单的log模块-超越昨天的自己系列(4)
2013-06-07 16:35
246 查看
超越昨天的自己系列(4)
用maven构建项目优点太多了,强烈建议项目初期构建使用maven。log模块是[b]项目中必不可少的。一个个模块拼接起来,慢慢学习更方便的构建一个完整,牛逼的项目。[/b]通过这样的命令,会自动创建一个项目:
mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app
产生类似这样一个项目目录:
推荐:在pom.xml写依赖的时候可以通过下面这个网站来查询:
http://search.maven.org/
pom.xml的配置如下:
<project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0 </modelVersion> <groupId>com.kkk.wap </groupId> <artifactId>testapp</artifactId> <version>1.0-SNAPSHOT </version> <packaging>jar </packaging> <name>testapp</name> <url>http://maven.apache.org </url> <properties> <project.build.sourceEncoding> UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.0.13</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
在项目根目录执行:mvn install 命令
会下载一下jar包:
测试类:
/** * Hello world! * */ public class App { private static Logger logger = LoggerFactory .getLogger ( App. class ); public static void main ( String [] args ){ logger .info ( "App said:show me the money!") ; System .out . println( "Hello World!" ) ; logger .info ( "you said:yo!yo!") ; try { String s = "12w" ; Integer .parseInt ( s) ; } catch (Exception e) { logger .error ( "you have a big poblem:" + e ) ; } } }
logback.xml的配置:
<? xml version ="1.0" encoding= "UTF-8" ?> <!-- Logback Configuration. --> <configuration debug = "false"> <appender name ="AllLOG" class ="ch.qos.logback.core.rolling.RollingFileAppender" > <file> d:/allLog.log</file> <encoding> UTF-8</encoding> <rollingPolicy class ="ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <FileNamePattern> d:/allLog.%d{yyyy-MM- dd}.log </FileNamePattern> </rollingPolicy> <append> true</append> <layout class ="ch.qos.logback.classic.PatternLayout" > <pattern> <![CDATA[ %n%-4r [%d{yyyy-MM-dd HH:mm:ss} %X{productionMode}] - %X{method} %X{requestURIWithQueryString} [ip=%X{remoteAddr}, ref=%X{referrer}, ua=%X{userAgent}, sid=%X{cookie.JSESSIONID}]%n %-5level %logger{35} - %m%n ]]> </pattern> </layout> </appender> <root> <level value = "info" /> <appender-ref ref = "AllLOG" /> </root> </configuration>
[align=left] [/align]
[align=left]解释一下:日志打在d盘的allLog文件夹下,每一天打完日志他会修改自己名字为d:/allLog.%d{yyyy-MM- dd}.log 这样的格式。注意正在打的日志是在allLog.log里。[/align]
[align=left] [/align]
[align=left]关于logback.xml配置可以参考博文:[/align]
[align=left] [/align]
[align=left]http://blog.csdn.net/haidage/article/details/6794509[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]log输出结果:[/align]
[align=left] [/align]
419 [2013-06-07 16:02:22 ] - [ip=, ref=, ua=, sid=] INFO com.kkk.wap.App - App said:show me the money! 434 [2013-06-07 16:02:22 ] - [ip=, ref=, ua=, sid=] INFO com.kkk.wap.App - you said:yo!yo! 435 [2013-06-07 16:02:22 ] - [ip=, ref=, ua=, sid=] ERROR com.kkk.wap.App - you have a big poblem:java.lang.NumberFormatException: For input string: "12w"
相关文章推荐
- maven为不同环境打包(hibernate)-超越昨天的自己系列(6)
- jms两种模式例子-超越昨天的自己系列(2)
- node 同步js代码-超越昨天的自己系列(5)
- 时间作为横轴的图表(morris.js)超越昨天的自己系列(8)
- node.js初探-超越昨天的自己系列(3)
- 关于分页选中问题-超越昨天的自己系列(9)
- 简单的spring,springmvc,mybatis,maven,mysql,mongodb的一些配置文件,自己用的
- ActiveMQ-超越昨天的自己系列(1)
- maven学习系列2----maven简单配置
- java进程性能分析步骤-超越昨天的自己系列(11)
- Collections.reverse 代码思考-超越昨天的自己系列(13)
- 快速用springmvc搭建web应用-超越昨天的自己系列(10)
- crontab 移动日志-超越昨天的自己系列(12)
- HashMap归档-超越昨天的自己系列
- Spring Boot 揭秘与实战 自己实现一个简单的自动配置模块
- Maven系列五:多模块项目中的聚合和继承
- Maven中如何配置WAR依赖WAR和JAR的多模块项目结构
- NET简单的一个画图程序 使用简单 自己可以相关自己的内容进行配置就可以使用了
- Maven中如何配置WAR依赖WAR和JAR的多模块项目结构
- myeclipse中自己手动配置maven