5.
6.    <!-- ========================== ⾃定义输出格式说明================================ -->
7.      <!-- %p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL -->
8.      <!-- %r 输出⾃应⽤启动到输出该log信息耗费的毫秒数  -->
9.      <!-- %c 输出所属的类⽬,通常就是所在类的全名 -->
10. <!-- %t 输出产⽣该⽇志事件的线程名 -->
11. <!-- %n 输出⼀个回车换⾏符,Windows平台为“/r/n”,Unix平台为“/n” -->
12. <!-- %d 输出⽇志时间点的⽇期或时间,默认格式为ISO8601,也可以在其后指定格式,⽐如:%d{yyy MMM dd HH:mm:ss,SSS},输
出类似:2002年10⽉18⽇ 22:10:28,921  -->
13. <!-- %l 输出⽇志事件的发⽣位置,包括类⽬名、发⽣的线程,以及在代码中的⾏数。举例:Testlo4.main(TestLog4.java:10)  -->
14. <!-- ========================================================================== -->
15.
1. <!-- ========================== 输出⽅式说明================================ -->
2. <!-- Log4j提供的appender有以下⼏种:  -->
3. <!-- org.apache.log4j.ConsoleAppender(控制台),  -->
4. <!-- org.apache.log4j.FileAppender(⽂件),  -->
5. <!-- org.apache.log4j.DailyRollingFileAppender(每天产⽣⼀个⽇志⽂件), -->
6. <!-- org.apache.log4j.RollingFileAppender(⽂件⼤⼩到达指定尺⼨的时候产⽣⼀个新的⽂件),  -->
7. <!-- org.apache.log4j.WriterAppender(将⽇志信息以流格式发送到任意指定的地⽅)  -->
8. <!-- ========================================================================== -->
9.
10. <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11. <!-- <param name="Target" value="System.out"/> -->
12. <layout class="org.apache.log4j.PatternLayout">
13. <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c  Method: %l ]%n%p:%m%n"/>
14. </layout>
15. <!--  <filter class="org.apache.log4j.varia.LevelRangeFilter">
16. <param name="LevelMin" value="DEBUG"/>
17. <param name="LevelMax" value="DEBUG"/>
18. </filter> -->
19. </appender>
20. <!-- output the debug  -->
21. <!--  <appender name="log4jDebug" class="org.apache.log4j.DailyRollingFileAppender">
22. <param name="File" value="log_"/>
23. <param name="MaxFileSize" value="KB"/>
24. <param name="MaxBackupIndex" value="2"/> -->
25. <appender name="log4jDebug"  class="org.lling.RollingFileAppender">
26. <param name="Append" value="true"/>
27. <rollingPolicy  class="org.lling.TimeBasedRollingPolicy">
28. <param name="FileNamePattern" value="./log/log_%d{yyyy-MM-dd}.log" />
29. </rollingPolicy>
30. <layout class="org.apache.log4j.PatternLayout">
31. <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c Method: %l ]%n%p:%m%n"/>
32. </layout>
33. <filter class="org.apache.log4j.varia.LevelRangeFilter">
34. <param name="LevelMin" value="DEBUG"/>
35. <param name="LevelMax" value="DEBUG"/>
36. </filter>
37. </appender>
38. <!--  <appender name="log4jInfo" class="org.apache.log4j.DailyRollingFileAppender">
39. <param name="File" value="log_"/>
40. <param name="DatePattern" value="'.log'yyyy-MM-dd"/>
41. <param name="Append" value="true"/>
42. <param name="MaxFileSize" value="5KB"/>
43. <param name="MaxBackupIndex" value="2"/> -->
44. <appender name="log4jInfo"  class="org.lling.RollingFileAppender">
45. <param name="Append" value="true"/>
46. <rollingPolicy  class="org.lling.TimeBasedRollingPolicy">xml标签大全
47. <param name="FileNamePattern" value="./log/log_%d{yyyy-MM-dd}.log" />
48. </rollingPolicy>
49. <layout class="org.apache.log4j.PatternLayout">
50. <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c  Method: %l ]%n%p:%m%n"/>
51. </layout>
52. <filter class="org.apache.log4j.varia.LevelRangeFilter">
53. <param name="LevelMin" value="INFO"/>
54. <param name="LevelMax" value="INFO"/>
55. </filter>
56. </appender>
57. <!--  <appender name="log4jWarn" class="org.apache.log4j.DailyRollingFileAppender">
58. <param name="File" value="/log_"/>
59. <param name="DatePattern" value="'.log'yyyy-MM-dd"/>
60. <param name="Append" value="true"/>
61. <param name="MaxFileSize" value="5KB"/>
62. <param name="MaxBackupIndex" value="2"/> -->
63. <appender name="log4jWarn" class="org.lling.RollingFileAppender">
64. <param name="Append" value="true"/>
65. <rollingPolicy  class="org.lling.TimeBasedRollingPolicy">
66. <param name="FileNamePattern" value="./log/log_%d{yyyy-MM-dd}.log" />
67. </rollingPolicy>
68. <layout class="org.apache.log4j.PatternLayout">
69. <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c Method: %l ]%n%p:%m%n"/>
70. </layout>
71. <filter class="org.apache.log4j.varia.LevelRangeFilter">
72. <param name="LevelMin" value="WARN"/>
73. <param name="LevelMax" value="WARN"/>
74. </filter>
75. </appender>
76. <!--  <appender name="log4jError" class="org.apache.log4j.DailyRollingFileAppender"> -->
77. <appender name="log4jError"  class="org.lling.RollingFileAppender">
78. <!--  <param name="File" value="/error_"/>
79. <param name="DatePattern" value="'.log'yyyy-MM-dd"/> -->
80. <param name="Append" value="true"/>
81. <rollingPolicy  class="org.lling.TimeBasedRollingPolicy">
82. <param name="FileNamePattern" value="./log/error_%d{yyyy-MM-dd}.log" />
83. </rollingPolicy>
84.
85.      <!--  <param name="MaxFileSize" value="5KB"/> -->
86.      <!--  <param name="MaxBackupIndex" value="2"/> -->
87.        <layout class="org.apache.log4j.PatternLayout">
88.              <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c Method: %l
]%n%p:%m%n"/>
89.        </layout>
90.        <filter class="org.apache.log4j.varia.LevelRangeFilter">
91.            <param name="LevelMin" value="ERROR"/>
92.            <param name="LevelMax" value="ERROR"/>
93.        </filter>
94.    </appender>
95.  <!--通过<category></category>的定义可以将各个包中的类⽇志输出到不同的⽇志⽂件中-->
96.    <!--    <category name="">
97.            <priority value="debug" />
98.            <appender-ref ref="log4jTestLogInfo" />
99.            <appender-ref ref="log4jTestDebug" />
100.        </category> -->
101.  <appender name="MAIL"
102.      class="org.apache.log4j.SMTPAppender">
103.      <param name="threshold" value="debug" />
104.      <!-- ⽇志的错误级别
105.        <param name="threshold" value="error"/>
106.      -->
107.      <!-- 缓存⽂件⼤⼩,⽇志达到512K时发送Email -->
108.      <param name="BufferSize" value="512" /><!-- 单位K -->
109.      <param name="From" value="test@163" />
110.      <param name="SMTPHost" value="smtp.163" />
111.      <param name="Subject" value="juyee-log4jMessage" />
112.      <param name="To" value="test@163" />
113.      <param name="SMTPUsername" value="test" />
114.      <param name="SMTPPassword" value="test" />
115.      <layout class="org.apache.log4j.PatternLayout">
116.        <param name="ConversionPattern"
117.        value="%-d{yyyy-MM-dd HH:mm:ss.SSS a} [%p]-[%c] %m%n" />
118.      </layout>
119.    </appender>
120.
121.
122.      <root>
123.        <priority value="debug"/>
124.        <appender-ref ref="CONSOLE" />
125.        <appender-ref ref="log4jDebug" />
126.        <appender-ref ref="log4jInfo" />
127.        <appender-ref ref="log4jWarn" />
128.        <appender-ref ref="log4jError" />
129.        <!-- <appender-ref ref="MAIL" /> -->
130.    </root>
131. </log4j:configuration>
log4j.properties⽂件配置模板:
1. # priority :debug<info<warn<error
2.
#you cannot specify every priority with different file for log4j
3.
4.
5.
#console
6.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
7.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
8.
log4j.appender.stdout.layout.ConversionPattern= [%d{yyyy-MM-dd HH:mm:ss a}]:%p %l%m%n
9.
#info log
10.
log4j.logger.info=info
11.
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
12.
log4j.appender.info.DatePattern='_'yyyy-MM-dd'.log'
13.
log4j.appender.info.File=./src/com/hp/log/info.log
14.
log4j.appender.info.Append=true
15.
log4j.appender.info.Threshold=INFO
16.
log4j.appender.info.layout=org.apache.log4j.PatternLayout
17.
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n 18.
#debug log
19.
log4j.logger.debug=debug
20.
log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender
21.
log4j.appender.debug.DatePattern='_'yyyy-MM-dd'.log'
22.
log4j.appender.debug.File=./src/com/hp/log/debug.log
23.
log4j.appender.debug.Append=true
24.
log4j.appender.debug.Threshold=DEBUG
25.
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
26.
log4j.appender.debug.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n 27.
#warn log
28.
log4j.logger.warn=warn
29.
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
30.
log4j.appender.warn.DatePattern='_'yyyy-MM-dd'.log'
31.
log4j.appender.warn.File=./src/com/hp/log/warn.log
32.
log4j.appender.warn.Append=true
33.
log4j.appender.warn.Threshold=WARN
34.
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
35.
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n 36.
#error
37.
=error
38.
= org.apache.log4j.DailyRollingFileAppender
39.
DatePattern='_'yyyy-MM-dd'.log'
40.
File = ./src/com/hp/log/error.log
41.
Append = true
42.
Threshold = ERROR
43.
layout = org.apache.log4j.PatternLayout
44.
layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

ibatis的if标签
« 上一篇
智能会议系统(16)---Linphone配置大全
下一篇 »

发表评论

推荐文章

热门文章

最新文章

标签列表