Article directory
application
import android.util.Log;
Log.v();
Log.d();
Log.i();
Log.w();
Log.e();
Log.wtf();
Log.wtfStack();
framework java
import android.util.Slog;
Slog.v();
Slog.d();
Slog.i();
Slog.w();
Slog.e();
Slog.wtf();
Slog.wtfQuiet();
Slog.wtfStack();
framework native
c language style
#include <cutils/log.h>
LOG_ALWAYS_FATAL_IF(...);
LOG_ALWAYS_FATAL(...);
LOG_FATAL_IF(...);
LOG_FATAL(...);
ALOG_ASSERT(...);
ALOGV(...);
ALOGV_IF(...);
ALOGD(...);
ALOGD_IF(...);
ALOGI(...);
ALOGI_IF(...);
ALOGW(...);
ALOGW_IF(...);
ALOGE(...);
ALOGE_IF(...);
c++ style
#include <android-base/logging.h>
LOG(VERBOSE) << "We didn't expect to reach here";
LOG(DEBUG) << "We didn't expect to reach here";
LOG(INFO) << "We didn't expect to reach here";
LOG(WARNING) << "We didn't expect to reach here";
LOG(ERROR) << "We didn't expect to reach here";
LOG(FATAL_WITHOUT_ABORT) << "We didn't expect to reach here";
LOG(FATAL) << "We didn't expect to reach here";
native stack print
1、进入对应的cpp文件,放开#define LOG_NDEBUG 0注释,且变成#define LOG_NDEBUG 1
2、声明头文件
#include<utils/CallStack.h>
#include<utils/Log.h>
3、调用方法:
android::CallStack stack;
stack.update();
stack.log(debug); //输出到logcat
4、mk或者bp中需要链接以下so库:
libutils
libcutils
HAL
#include <utils/Log.h>
LOG_ALWAYS_FATAL_IF(...);
LOG_ALWAYS_FATAL(...);
LOG_FATAL_IF(...);
LOG_FATAL(...);
ALOG_ASSERT(...);
ALOGV(...);
ALOGV_IF(...);
ALOGD(...);
ALOGD_IF(...);
ALOGI(...);
ALOGI_IF(...);
ALOGW(...);
ALOGW_IF(...);
ALOGE(...);
ALOGE_IF(...);
Kernel
Through cat /proc/sys/kernel/printk
this file, view the default log level of the system
xxxxx:/ # cat /proc/sys/kernel/printk
7 4 1 7
From left to right:
-
7
It representsconsole_loglevel
: the log level of the console, andprintk
the output information will be printed to the console with a higher priority than it -
4
Representsdefault_message_loglevel
: the default message log level, ifprintk
no priority is specified, the default priority is it -
1
Representsminimum_console_loglevel
: the lowest console log level, the minimum value that the console log level can be set -
7
Representsdefault_console_loglevel
: the default console log level, the default value of the console log level
The level can be changed console_loglevel
to allow more kernel logs to be printed
xxxxx:/ # echo 0 > /proc/sys/kernel/printk
printk(KERN_EMERG "KERN_EMERG\n");
printk(KERN_ALERT "KERN_ALERT\n");
printk(KERN_CRIT "KERN_CRIT\n");
printk(KERN_ERR "KERN_ERR\n");
printk(KERN_WARNING "KERN_WARNING\n");
printk(KERN_NOTICE "KERN_NOTICE\n");
printk(KERN_INFO "KERN_INFO\n");
printk(KERN_DEBUG "KERN_DEBUG\n");