1 package ai.suanzi.rtmpclient;
4 Copyright 2011 Rolf Kulemann
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
19 import android.os.Environment;
21 import org.apache.log4j.Level;
22 import de.mindpipe.android.logging.log4j.LogConfigurator;
25 import java.util.Date;
31 public class ConfigureLog4J {
32 //日志级别优先度从高到低:OFF(关闭),FATAL(致命),ERROR(错误),WARN(警告),INFO(信息),DEBUG(调试),ALL(打开所有的日志,我的理解与DEBUG级别好像没有什么区别得)
33 //Log4j建议只使用FATAL ,ERROR ,WARN ,INFO ,DEBUG这五个级别。
34 // "yyyy-MM-dd");// 日志的输出格式
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";
45 logConfigurator.setFileName(fileName);
46 //设置root日志输出级别 默认为DEBUG
47 logConfigurator.setRootLevel(Level.DEBUG);
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");
55 logConfigurator.setMaxFileSize(1024 * 1024 * 5);
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);
65 logConfigurator.setResetConfiguration(true);
66 //是否显示内部初始化日志,默认为false
67 logConfigurator.setInternalDebugging(false);
69 logConfigurator.configure();