public class Demo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
TextView tv = new TextView(this); tv.setText("Hello, I am andy lee!"); setContentView(tv);
Log.i(TAG, "this is a log.i message"); Log.v(TAG, "this is a log.v message"); Log.d(TAG, "this is a log.d message"); Log.w(TAG, "this is a log.w message"); Log.e(TAG, "this is a log.e message"); Log.a(TAG, "this is a log.a message"); } }
/* define log tag */ #ifdef LOG_TAG #undef LOG_TAG #define LOG_TAG "app" #endif int main() { ALOGV("Verbose: _app"); ALOGD("Debug: _app"); ALOGI("Info: _app"); ALOGW("Warn: _app"); ALOGE("Error: _app"); printf("I am andy lee!\n"); return 0; }
##Android上的log格式 Log信息的格式及详解如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
tv_sec tv_nsec priority pid tid tag messageLen Message
tag: 标签 tv_sec & tv_nsec: 日志的时间戳 pid: 打印日志的进程ID tid: 打印日志的线程ID Priority: 日志等级(或优先级),取值如下 V — Verbose (lowest priority) D — Debug I — Info W — Warning E — Error A — Assert