자바 혹은 안드로이드를 개발할 때 로그 정보는 더 없이 유용한 정보이다.

난공불락 같아 보이는 에러도 로그를 출력해 보면 거의 대부분 문제를 해결하게 된다.

이클립스로 개발 한다면 로그 정보를 보는 방법은 매우 간단하다.

그런에 여기서는 로그의 정보를 파일로 저장하는 방법에 대해서 살펴본다.


우선 adb.exe가 설치되어 있는 위치로 이동해서 도스 창(커맨더 창)을 adb가 있는 위치에서 연다.

그리고 logcat을 저장하기 위해 사용할수 있는 명령어 형태는 다음과 같다.


Usage: logcat [options] [filterspecs]


options include:

  -s              Set default filter to silent.

                  Like specifying filterspec '*:s'

  -f <filename>   Log to file. Default to stdout

  -r [<kbytes>]   Rotate log every kbytes. (16 if unspecified). Requires -f

  -n <count>      Sets max number of rotated logs to <count>, default 4

  -v <format>     Sets the log print format, where <format> is one of:

                  brief process tag thread raw time threadtime long

  -c              clear (flush) the entire log and exit

  -d              dump the log and then exit (don't block)

  -t <count>      print only the most recent <count> lines (implies -d)

  -t '<time>'     print most recent lines since specified time (implies -d)

  -T <count>      print only the most recent <count> lines (does not imply -d)

  -T '<time>'     print most recent lines since specified time (not imply -d)

                  count is pure numerical, time is 'MM-DD hh:mm:ss.mmm'

  -g              get the size of the log's ring buffer and exit

  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio',

                  'events', 'crash' or 'all'. Multiple -b parameters are

                  allowed and results are interleaved. The default is

                  -b main -b system -b crash.

  -B              output the log in binary.

  -S              output statistics.

  -G <size>       set size of log ring buffer, may suffix with K or M.

  -p              print prune white and ~black list. Service is specified as

                  UID, UID/PID or /PID. Weighed for quicker pruning if prefix

                  with ~, otherwise weighed for longevity if unadorned. All

                  other pruning activity is oldest first. Special case ~!

                  represents an automatic quicker pruning for the noisiest

                  UID as determined by the current statistics.

  -P '<list> ...' set prune white and ~black list, using same format as

                  printed above. Must be quoted.


filterspecs are a series of 

  <tag>[:priority]


where <tag> is a log component tag (or * for all) and priority is:


  V    Verbose

  D    Debug

  I    Info

  W    Warn

  E    Error

  F    Fatal

  S    Silent (supress all output)


'*' means '*:d' and <tag> by itself means <tag>:v

If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.

If no filterspec is found, filter defaults to '*:I'

If not specified with -v, format is set from ANDROID_PRINTF_LOG

or defaults to "brief"


로그 정보에는 몇가지 종류가 있다.

v : 온갖 종류의 로그 전부다를 보여준다.

d, e, ...


그 중에서 여기서는 e에 대한 정보만을 출력하는 정보만을 파일로 저장해 본다.

다른 필터들(d, v, i...)도 동일한 방식으로 저장한다.

사용 방식은 다음과 같다.


Usage: logcat [options] [filterspecs]


따라서 다음과 같이 하면된다.


adb logcat *:e > D:\temp\kkk.txt


위와 같이 명령하면 D:\temp 폴더 아래에 kkk.txt라는 이름으로 로그 중 e(에러) 정보만을 파일로 저장한다.




+ Recent posts