ITeye博客

android 工程 日志输出 附源码

leequer · 2010-03-02 15:58 · android · 移动开发 · Markdown

1.日志输出:我们开发时常会在控制台输出数据 首先我们将eclipse的android的控制台的日志输出等级设置为infor window->prefernces 然后在activity的代码中添加Log日志;


package cn.aboutlog.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class AboutLogActivity extends Activity {
	private static final String TAGSTRING = "AboutLogActivity";//shift+ctrl+x 大写快捷键
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        /**
         * Log 日志类
         * 这里我们输出AboutLogActivity这个类被实例化的信息
         * i(String,String);这里的两个参数,第一个参数是标志位,第二个
         * 参数是显示的信息,这里建议将标志位的参数设置为类名;
         * 这个方法就是显示信息用的
         * e(。。。);这个是用来显示错误信息的
         * d(。。。);这个用来显示debug信息的
         * 控制台是在window->show view->other->android->logcat
         */
       // Log.i(TAGSTRING, "实例化AboutLogActivity类");不支持中文
        Log.i(TAGSTRING, "AboutLogActivity created");
    }
}

控制台是在window--show view--other--android--logcat 想快速找到你的日志使用过滤器 点击logcat中的绿色的加号 添加一个过滤器 填写的标签就是你程序中定义的那个tag 效果很明显

评论(1)

  1. #1 楼 · zhouxiaoli521 · 2010-04-04 22:50

    其实system.out.println()在logcat 也是可以看到的

评论功能维护中,当前仅展示历史评论。