로그인

검색

JAVA/Android
2013.05.28 11:05

logcat 사용법

MoA
조회 수 4055 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄

adb logcat -s 필터명:옵션

 

옵션의 종류는 다음과 같다.

V,D,I,W,E,F,S

각각 Verbose, Debug, Info, Warn, Error, Fatal, Silent를 의미한다.

 

소스코드에서

Log.d("update", "abcdefg");

이런 식으로 로그를 걸어두었으면,

 

adb logcat -s update:D

이런 식으로 Logcat을 콘솔에서 구동시켜 해당 로그만 조회할 수 있다.

 

* 시간 정보를 보는 방법

logcat -v time

 

Enabling logcat Logging

The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcatcommand.

Using logcat Commands

You can use the logcat command to view and follow the contents of the system's log buffers. The general usage is:

[adb] logcat [<option>] ... [<filter-spec>] ...

The sections below explain filter specifications and the command options. See Listing of logcat Command Options for a summary of options.

You can use the logcat command from your development computer or from a remote adb shell in an emulator/device instance. To view log output in your development computer, you use

$ adb logcat

and from a remote adb shell you use

# logcat

Filtering Log Output

Every Android log message has a tag and a priority associated with it.

  • The tag of a log message is a short string indicating the system component from which the message originates (for example, "View" for the view system).
  • The priority is one of the following character values, ordered from lowest to highest priority:
    • V — Verbose (lowest priority)
    • D — Debug
    • I — Info (default priority)
    • W — Warning
    • E — Error
    • F — Fatal
    • S — Silent (highest priority, on which nothing is ever printed)

You can obtain a list of tags used in the system, together with priorities, by running logcat and observing the first two columns of each message, given as <priority>/<tag>.

Here's an example of logcat output that shows that the message relates to priority level "I" and tag "ActivityManager":

I/ActivityManager(  585): Starting activity: Intent { action=android.intent.action...}

To reduce the log output to a manageable level, you can restrict log output using filter expressions. Filter expressions let you indicate to the system the tags-priority combinations that you are interested in — the system suppresses other messages for the specified tags.

A filter expression follows this format tag:priority ..., where tag indicates the tag of interest and priority indicates theminimum level of priority to report for that tag. Messages for that tag at or above the specified priority are written to the log. You can supply any number of tag:priority specifications in a single filter expression. The series of specifications is whitespace-delimited. The default output is to show all log messages with the Info priority (*:I).

Here's an example of a filter expression that suppresses all log messages except those with the tag "ActivityManager", at priority "Info" or above, and all log messages with tag "MyApp", with priority "Debug" or above:

adb logcat ActivityManager:I MyApp:D *:S

The final element in the above expression, *:S, sets the priority level for all tags to "silent", thus ensuring only log messages with "View" and "MyApp" are displayed. Using *:S is an excellent way to ensure that log output is restricted to the filters that you have explicitly specified — it lets your filters serve as a "whitelist" for log output.

The following filter expression displays all log messages with priority level "warning" and higher, on all tags:

adb logcat *:W

If you're running logcat from your development computer (versus running it on a remote adb shell), you can also set a default filter expression by exporting a value for the environment variable ANDROID_LOG_TAGS:

export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"

Note that ANDROID_LOG_TAGS filter is not exported to the emulator/device instance, if you are running logcat from a remote shell or using adb shell logcat.

Controlling Log Output Format

Log messages contain a number of metadata fields, in addition to the tag and priority. You can modify the output format for messages so that they display a specific metadata field. To do so, you use the -v option and specify one of the supported output formats listed below.

  • brief — Display priority/tag and PID of originating process (the default format).
  • process — Display PID only.
  • tag — Display the priority/tag only.
  • thread — Display process:thread and priority/tag only.
  • raw — Display the raw log message, with no other metadata fields.
  • time — Display the date, invocation time, priority/tag, and PID of the originating process.
  • long — Display all metadata fields and separate messages with a blank lines.

When starting logcat, you can specify the output format you want by using the -v option:

[adb] logcat [-v <format>]

Here's an example that shows how to generate messages in thread output format:

adb logcat -v thread

Note that you can only specify one output format with the -v option.

Viewing Alternative Log Buffers

The Android logging system keeps multiple circular buffers for log messages, and not all of the log messages are sent to the default circular buffer. To see additional log messages, you can start logcat with the -b option, to request viewing of an alternate circular buffer. You can view any of these alternate buffers:

  • radio — View the buffer that contains radio/telephony related messages.
  • events — View the buffer containing events-related messages.
  • main — View the main log buffer (default)

The usage of the -b option is:

[adb] logcat [-b <buffer>]

Here's an example of how to view a log buffer containing radio and telephony messages:

adb logcat -b radio

Viewing stdout and stderr

By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null. In processes that run the Dalvik VM, you can have the system write a copy of the output to the log file. In this case, the system writes the messages to the log using the log tags stdout and stderr, both with priority I.

To route the output in this way, you stop a running emulator/device instance and then use the shell command setprop to enable the redirection of output. Here's how you do it:

$ adb shell stop
$ adb shell setprop log
.redirect-stdio true
$ adb shell start

The system retains this setting until you terminate the emulator/device instance. To use the setting as a default on the emulator/device instance, you can add an entry to /data/local.prop on the device.

Listing of logcat Command Options

OptionDescription
-b <buffer>Loads an alternate log buffer for viewing, such as event or radio. The main buffer is used by default. See Viewing Alternative Log Buffers.
-cClears (flushes) the entire log and exits.
-dDumps the log to the screen and exits.
-f <filename>Writes log message output to <filename>. The default is stdout.
-gPrints the size of the specified log buffer and exits.
-n <count>Sets the maximum number of rotated logs to <count>. The default value is 4. Requires the -r option.
-r <kbytes>Rotates the log file every <kbytes> of output. The default value is 16. Requires the -f option.
-sSets the default filter spec to silent.
-v <format>Sets the output format for log messages. The default is brief format. For a list of supported formats, see Controlling Log Output Format.

원하는 로그만 보는 법(테그 사용법)

  adb logcat SJ:V 

이렇게 설정하면 Tag가 SJ인 로그중 Vervose 이상인 로그가 보인다.

 (Log.i( "SJ", ... ) 출력한 로그먄 보여진다 )

[출처] adb logcat ( filtering log output )|작성자 홍길동

(

(테그의 우선순위 :  Verbose / Debug / Info / Warning / Error / Fatal / Silent)

 adb logcat SJ:V  SJMAIN:V *:S

이렇게 복수의 필터도 설정 가능 

SJ, SJMAIN 테그를 제외한 다른 메세지는 보지 않는다라고 설정한 상태

 

자, 이렇게 필터를 항상 command line에서 입력할때 마다 써야 하는가하면

그렇지는 않다

이렇게 하면된다.

메뉴얼에서는 환경변수를 export하면된다고 기술되어있는데

이는 리눅스에서 동작하는 상황이므로 대다수의 윈도우 사용자는 안되는 줄 알고 있는데

이렇게 하면 된다.

만약에 아래 같은 필터를 설정한다면

 adb logcat SJ:V  SJMAIN:V *:S

 

환경 변수 ANDROID_LOG_TAGS 세팅하여 놓으면

export ANDROID_LOG_TAGS= SJ:V  SJMAIN:V *:S

이후로는 

 adb logcat 

라고만 명령어를 쳐도 필터가 세팅된 상태로 동작한다.

 

이는 한글을 보기 위해 코드페이지를 (chcp 65001) 유니코드로 바꾼후에

batch 파일(.bat)이 동작하지 않는 상황에서 매우 유용하다.

set 변수는 cmd 창을 닫기 전까지

항상 유효하다.

중간에 

set ANDROID_LOG_TAGS= ~~~~

로 변경도 가능하다.

 

 

혹시라도 time stemp를 붙이고 싶으면

   adb logcat -v time

 

작업내용을 File로 저장해야 하는 경우 방법

파일 패스는 컴퓨터 패스가 아닌 안드로이드 자체 패스를 이용해야한다.

  adb logcat -f /data/data/sj.chess/Log.txt

 (일반적으로 data/data/apkName 은 쓰기 권한이 있으므로 여기에 남기면 됩니다.)

 아니면 특정 디렉토리에 쓰기 권한을 주고 그쪽으로 모아도 됩니다.


http://www.placeo.pe.kr/index.php?document_srl=2253&mid=DevelopmentAndroid


공식사이트 로그캣 문서 번역 자료

http://codemuri.tistory.com/entry/%EB%B2%88%EC%97%AD-Log-%EC%9D%BD%EA%B3%A0-%EC%93%B0%EA%B8%B0

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views5346
    read more
  2. CPaneDialog의 context menu 안뜨게 하기

    Date2013.06.12 CategoryAPI/MFC ByMoA Views1237
    Read More
  3. 리스트 컨트롤 클릭 이벤트

    Date2013.06.12 CategoryAPI/MFC ByMoA Views1175
    Read More
  4. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views835
    Read More
  5. 시스템 분석을 위한 쉘 명령어

    Date2013.05.28 CategoryJAVA/Android ByMoA Views1076
    Read More
  6. logcat 사용법

    Date2013.05.28 CategoryJAVA/Android ByMoA Views4055
    Read More
  7. 리스트뷰에 체크박스 추가 예제

    Date2013.05.24 CategoryJAVA/Android ByMoA Views1423
    Read More
  8. PackageBroadcastReceiver 구현

    Date2013.05.22 CategoryJAVA/Android ByMoA Views1083
    Read More
  9. 안드로이드 초간단 리스트뷰 사용법

    Date2013.04.10 CategoryJAVA/Android ByMoA Views715
    Read More
  10. 안드로이드 프로세스 확인

    Date2013.04.09 CategoryJAVA/Android ByMoA Views834
    Read More
  11. 안드로이드 개발 참고 사이트

    Date2013.03.31 CategoryJAVA/Android ByMoA Views848
    Read More
  12. 안드로이드 어플 개발 사이트

    Date2013.03.11 CategoryJAVA/Android ByMoA Views956
    Read More
  13. 이클립스에서 ADT 설치시 에러 해결

    Date2013.03.09 CategoryJAVA/Android ByMoA Views1150
    Read More
  14. Visual Studio Debug Tips

    Date2013.02.19 CategoryTool/etc ByMoA Views972
    Read More
  15. Great summary cheat sheet (OpenCV)

    Date2013.01.04 CategorySite ByMoA Views1158
    Read More
  16. C++에서 base64로 인코딩

    Date2012.11.15 CategoryC/C++ ByNaya Views1134
    Read More
  17. Base64 decoder (binary file로 저장)

    Date2012.11.15 CategorySite ByNaya Views1092
    Read More
  18. 특정 자료형의 데이터를 binary(hex값, 2진수값)으로 변환

    Date2012.11.15 CategorySite ByNaya Views1115
    Read More
  19. Dumpbin.exe 사용

    Date2012.10.21 CategoryReversing ByNaya Views888
    Read More
  20. [OpenCV] 얼굴 인식 예제

    Date2012.10.14 CategoryLibrary ByMoA Views1992
    Read More
  21. 코드 실행 시간 계산

    Date2012.09.27 CategoryC/C++ ByNaya Views1265
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 Next
/ 15