Android 는 자신의 LOG 정 보 를 실현 합 니 다.
1.커 널 개발 시 LOG 의 사용Android 커 널 은 Linux Kerne 2.36 을 기반 으로 하기 때문에 Linux Kernel 의 LOG 체 제 는 Android 커 널 에 도 적합 합 니 다.이것 은 바로 유명한 printk 로 C 언어의 printf 와 함께 유명 합 니 다.printf 와 유사 하 게 printk 는 포맷 된 입력 기능 을 제공 하 는 동시에 모든 LOG 메커니즘 의 특징 을 가지 고 있 습 니 다.로그 단계 의 지나친 기능 을 제공 합 니 다.printk 는 8 가지 로그 단 계 를 제공 합 니 다(
#define KERN_EMERG "<0>"  /* system is unusable   */ 
#define KERN_ALERT "<1>"  /* action must be taken immediately */ 
#define KERN_CRIT "<2>"  /* critical conditions   */ 
#deinfe KERN_ERR "<3>"  /* error conditions   */ 
#deinfe KERN_WARNING "<4>"  /* warning conditions   */ 
#deinfe KERN_NOTICE "<5>"  /* normal but significant condition */ 
#deinfe KERN_INFO "<6>"  /* informational   */ 
#deinfe KERN_DEBUG "<7>"  /* debug-level messages   */ printk(KERN_ALERT"This is the log printed by printk in linux kernel space.");
KERN_ALERT 는 로그 단 계 를 표시 합 니 다.뒤에 포맷 할 문자열 이 바짝 붙 어 있 습 니 다.
Android 시스템 에서 printk 가 출력 한 로그 정 보 는/proc/kmsg 에 저 장 됩 니 다./proc/kmsg 의 내용 을 보 려 면Android 커 널 소스 는 Ubuntu 에서 다운로드,컴 파일,설치문 서 를 참조 하여 배경 에서 시 뮬 레이 터 를 실행 하 십시오.
USER-NAME@MACHINE-NAME:~/Android$ emulator &
adb 셸 도구 시작:
USER-NAME@MACHINE-NAME:~/Android$ adb shell
/proc/kmsg 파일 보기:
root@android:/ # cat /proc/kmsg
2.사용자 공간 프로그램 개발 시 LOG 사용Android 시스템 은 사용자 공간 에서 경량급 logger 로그 시스템 을 제공 합 니 다.커 널 에서 이 루어 진 장치 구동 으로 사용자 공간의 logcat 도구 와 함께 사용 하면 디 버 깅 프로그램 을 편리 하 게 추적 할 수 있 습 니 다.안 드 로 이 드 시스템 에 서 는 각각 C/C++와 자바 언어 에 두 가지 서로 다른 logger 접근 인 터 페 이 스 를 제공 합 니 다.C/C++로그 인 터 페 이 스 는 일반적으로 하드웨어 추상 층 모듈 을 작성 하거나 JNI 방법 을 작성 할 때 사용 되 며,자바 인 터 페 이 스 는 일반적으로 응용 층 에서 앱 을 작성 할 때 사용 된다.
Android 시스템 의 C/C++로그 인 터 페 이 스 는 매크로 를 통 해 사 용 됩 니 다.시스템/core/include/android/log.h 에서 로그 의 단 계 를 정의 합 니 다:
/* 
 * Android log priority values, in ascending priority order. 
 */ 
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; 
/* 
 * This is the local tag used for the following simplified 
 * logging macros. You can change this preprocessor definition 
 * before using the other macros to change the tag. 
 */ 
#ifndef LOG_TAG 
#define LOG_TAG NULL 
#endif 
 
/* 
 * Simplified macro to send a verbose log message using the current LOG_TAG. 
 */ 
#ifndef LOGV 
#if LOG_NDEBUG 
#define LOGV(...) ((void)0) 
#else 
#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) 
#endif 
#endif 
 
/* 
 * Basic log message macro. 
 * 
 * Example: 
 * LOG(LOG_WARN, NULL, "Failed with error %d", errno); 
 * 
 * The second argument may be NULL or "" to indicate the "global" tag. 
 */ 
#ifndef LOG 
#define LOG(priority, tag, ...) \ 
  LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) 
#endif 
 
/* 
 * Log macro that allows you to specify a number for priority. 
 */ 
#ifndef LOG_PRI 
#define LOG_PRI(priority, tag, ...) \ 
  android_printLog(priority, tag, __VA_ARGS__) 
#endif 
 
/* 
 * ================================================================ 
 * 
 * The stuff in the rest of this file should not be used directly. 
 */ 
#define android_printLog(prio, tag, fmt...) \ 
  __android_log_print(prio, tag, fmt) #define LOG_TAG "MY LOG TAG"
#include
예 를 들 어 LOGV 를 사용 하면 됩 니 다.
LOGV("This is the log printed by LOGV in android user space.");
안 드 로 이 드 시스템 의 자바 로그 인 터 페 이 스 를 보십시오.Android 시스템 은 Frameworks 층 에서 Log 인 터 페 이 스 를 정의 합 니 다.
(frameworks/base/core/java/android/util/Log.java):
................................................ 
 
public final class 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; 
 
..................................................... 
 
 public static int v(String tag, String msg) { 
  return println_native(LOG_ID_MAIN, VERBOSE, tag, msg); 
 } 
 
 public static int v(String tag, String msg, Throwable tr) { 
  return println_native(LOG_ID_MAIN, VERBOSE, tag, msg + '
' + getStackTraceString(tr)); 
 } 
 
 public static int d(String tag, String msg) { 
  return println_native(LOG_ID_MAIN, DEBUG, tag, msg); 
 } 
 
 public static int d(String tag, String msg, Throwable tr) { 
  return println_native(LOG_ID_MAIN, DEBUG, tag, msg + '
' + getStackTraceString(tr)); 
 } 
 
 public static int i(String tag, String msg) { 
  return println_native(LOG_ID_MAIN, INFO, tag, msg); 
 } 
 
 public static int i(String tag, String msg, Throwable tr) { 
  return println_native(LOG_ID_MAIN, INFO, tag, msg + '
' + getStackTraceString(tr)); 
 } 
 
 public static int w(String tag, String msg) { 
  return println_native(LOG_ID_MAIN, WARN, tag, msg); 
 } 
 
 public static int w(String tag, String msg, Throwable tr) { 
  return println_native(LOG_ID_MAIN, WARN, tag, msg + '
' + getStackTraceString(tr)); 
 } 
 
 public static int w(String tag, Throwable tr) { 
  return println_native(LOG_ID_MAIN, WARN, tag, getStackTraceString(tr)); 
 } 
  
 public static int e(String tag, String msg) { 
  return println_native(LOG_ID_MAIN, ERROR, tag, msg); 
 } 
 
 public static int e(String tag, String msg, Throwable tr) { 
  return println_native(LOG_ID_MAIN, ERROR, tag, msg + '
' + getStackTraceString(tr)); 
 } 
 
.................................................................. private static final String LOG_TAG = "MY_LOG_TAG";
Log.i(LOG_TAG, "This is the log printed by Log.i in android user space.");
이 LOG 의 출력 을 보 려 면 logcat 도구 에 맞 출 수 있 습 니 다.Eclipse 환경 에서 시 뮬 레이 터 를 실행 하고 Android 플러그 인 을 설치 했다 면 간단 합 니 다.Eclipse 에서 직접 볼 수 있 습 니 다.
 
 자신 이 컴 파일 한 Android 소스 코드 프로젝트 에서 사용 하 는 경우 배경 에서 시 뮬 레이 터 를 실행 합 니 다.
USER-NAME@MACHINE-NAME:~/Android$ emulator &
adb 셸 도구 시작:
USER-NAME@MACHINE-NAME:~/Android$ adb shell
로그 cat 명령 으로 로그 보기:
root@android:/ # logcat
이렇게 하면 출력 로 그 를 볼 수 있 습 니 다.
이상 은 안 드 로 이 드 자체 의 LOG 정보 구현 방법 입 니 다.필요 한 친구 가 보 세 요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.