android log 定义

android log 优先级定义:

     java 层相关的定义在frameworks/base/core/Java/android/util/Log.java

6个优先级的log,

/**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.w.
     */
    public static final int WARN = 5;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    /**
     * Priority constant for the println method.
     */
    public static final int ASSERT = 7;

android系统有4种类型:

/** @hide */ public static final int LOG_ID_MAIN = 0;
    /** @hide */ public static final int LOG_ID_RADIO = 1;
    /** @hide */ public static final int LOG_ID_EVENTS = 2;
    /** @hide */ public static final int LOG_ID_SYSTEM = 3;
    /** @hide */ public static final int LOG_ID_CRASH = 4;


API:Log.v() Log.d() Log.i() Log.w() and Log.e()


native层中定义的priority(在system/core/include/android/log.h中

android系统有4种类型:

typedef enum log_id {
    LOG_ID_MIN = 0,

    LOG_ID_MAIN = 0,
    LOG_ID_RADIO = 1,
    LOG_ID_EVENTS = 2,
    LOG_ID_SYSTEM = 3,
    LOG_ID_CRASH = 4,

    LOG_ID_MAX
} log_id_t;

优先级:

typedef enum android_LogPriority {
    ANDROID_LOG_UNKNOWN = 0,
    ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
    ANDROID_LOG_VERBOSE,
    ANDROID_LOG_DEBUG,
    ANDROID_LOG_INFO,
    ANDROID_LOG_WARN,
    ANDROID_LOG_ERROR,
    ANDROID_LOG_FATAL,
    ANDROID_LOG_SILENT,     /* only for SetMinPriority(); must be last */
} android_LogPriority;

int __android_log_print(int prio, const char *tag,  const char *fmt, ...);
int __android_log_vprint(int prio, const char *tag,
                         const char *fmt, va_list ap);
int __android_log_write(int prio, const char *tag, const char *text);

system/core/include/cutils/log.h(system/core/include/log/ log.h)中定义了使用的API
 Simplified macro to send a  log message using the current LOG_TAG:
ALOGV();ALOGD();ALOGI();ALOGW();ALOGE();

Simplified macro to send a system log message using the current LOG_TAG.
SLOGV();SLOGD();SLOGI();SLOGW();SLOGE();

Simplified macro to send a radio log message using the current LOG_TAG.

RLOGV();RLOGD();RLOGI();RLOGW();RLOGE();

Basic log message macro:ALOG()

#ifndef ALOG
#define ALOG(priority, tag, ...) \
    LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
#endif

eg:

ALOG(LOG_WARN, NULL, "Failed with error %d", errno);


int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)

eg:

__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))








猜你喜欢

转载自blog.csdn.net/chengf223/article/details/78560052