6abb63d70672b80480393572bb61987e1affc885
[rtmpclient.git] / app / src / main / java / ai / suanzi / rtmpclient / ConfigureLog4J.java
1 package ai.suanzi.rtmpclient;
2
3 /*
4    Copyright 2011 Rolf Kulemann
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17  */
18
19 import android.os.Environment;
20
21 import org.apache.log4j.Level;
22 import de.mindpipe.android.logging.log4j.LogConfigurator;
23
24 import java.io.File;
25 import java.util.Date;
26
27
28 /**
29  * 日志设置
30  */
31 public class ConfigureLog4J {
32 //日志级别优先度从高到低:OFF(关闭),FATAL(致命),ERROR(错误),WARN(警告),INFO(信息),DEBUG(调试),ALL(打开所有的日志,我的理解与DEBUG级别好像没有什么区别得)
33 //Log4j建议只使用FATAL ,ERROR ,WARN ,INFO ,DEBUG这五个级别。
34     // "yyyy-MM-dd");// 日志的输出格式
35
36     public static void configure() {
37         final LogConfigurator logConfigurator = new LogConfigurator();
38         Date nowtime = new Date();
39         // String needWriteMessage = myLogSdf.format(nowtime);
40         //日志文件路径地址:SD卡下myc文件夹log文件夹的test文件
41         String fileName = Environment.getExternalStorageDirectory()
42                 + File.separator + "myc" + File.separator + "log"
43                 + File.separator + "test.log";
44         //设置文件名
45         logConfigurator.setFileName(fileName);
46         //设置root日志输出级别 默认为DEBUG
47         logConfigurator.setRootLevel(Level.DEBUG);
48         // 设置日志输出级别
49         logConfigurator.setLevel("org.apache", Level.INFO);
50         //设置 输出到日志文件的文字格式 默认 %d %-5p [%c{2}]-[%L] %m%n
51         logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
52         //设置输出到控制台的文字格式 默认%m%n
53         logConfigurator.setLogCatPattern("%m%n");
54         //设置总文件大小
55         logConfigurator.setMaxFileSize(1024 * 1024 * 5);
56         //设置最大产生的文件个数
57         logConfigurator.setMaxBackupSize(1);
58         //设置所有消息是否被立刻输出 默认为true,false 不输出
59         logConfigurator.setImmediateFlush(true);
60         //是否本地控制台打印输出 默认为true ,false不输出
61         logConfigurator.setUseLogCatAppender(true);
62         //设置是否启用文件附加,默认为true。false为覆盖文件
63         logConfigurator.setUseFileAppender(true);
64         //设置是否重置配置文件,默认为true
65         logConfigurator.setResetConfiguration(true);
66         //是否显示内部初始化日志,默认为false
67         logConfigurator.setInternalDebugging(false);
68
69         logConfigurator.configure();
70
71     }
72 }