码迷,mamicode.com
首页 > 移动开发 > 详细

27、android log日志

时间:2015-03-15 01:59:51      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

一、记住

加写sd卡权限

 

二、代码

技术分享
 1 package com.example.logtest;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 import org.apache.log4j.Appender;
 7 import org.apache.log4j.FileAppender;
 8 import org.apache.log4j.Logger;
 9 import org.apache.log4j.PatternLayout;
10 
11 
12 import android.app.Activity;
13 import android.os.Bundle;
14 import android.os.Environment;
15 import android.util.Log;
16 
17 
18 
19 public class MainActivity extends Activity {
20 
21     public static  Logger gLoggerTvMenu;
22     public static String pathTvMenuCache =  Environment.getExternalStorageDirectory()+File.separator+"5wei"+ File.separator+"TvMenuCache"+ File.separator;
23     
24     @Override
25     protected void onCreate(Bundle savedInstanceState) {
26         super.onCreate(savedInstanceState);
27         setContentView(R.layout.activity_main);
28         
29 
30         gLoggerTvMenu = Logger.getLogger("tvMenu");
31         PatternLayout tvMenuLayout = new PatternLayout("%d %p [%c] - %m%n");
32         try {
33             Appender tvMenuAppender = new FileAppender(tvMenuLayout,pathTvMenuCache+"tvMenu.log");
34             gLoggerTvMenu.addAppender(tvMenuAppender);
35         } catch (IOException e) {
36             // TODO Auto-generated catch block
37             Log.e("error", "wrong :"+e.getMessage());
38             e.printStackTrace();
39         }
40         
41         gLoggerTvMenu.debug("it is a test");
42     }
43 }
View Code

 

三、效果

在对应目录生成对应的日志文件

 

四、demo外链

http://pan.baidu.com/s/1dDCiS17

27、android log日志

标签:

原文地址:http://www.cnblogs.com/kunyashaw/p/4338693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!