로그 찍기

thsamajiki·2023년 6월 22일
0

Android

목록 보기
2/5

Log

  • 코딩을 할 때 코드의 흐름 및 프로그램 오류를 파악하기 위해 앱 외부로 출력하는 정보
  • 디버거를 사용할 수도 있지만 매번 디버깅할 포인트를 지정해야 하는 불편함이 있음.
  • 로그를 사용하면 한 번 설정으로 항상 해당 코드의 흐름을 쉽게 확인

어떤 언어, IDE를 통해 개발을 진행할때 떼어놓을 수 없는 것은 개발 과정에서 디버깅을 하고 로그를 확인해 프로그램이 중간중간 어떻게 동작하는지 확인하는 과정이 필요하다.



💡 Log 종류

안드로이드 스튜디오에서는 총 5가지의 로그 종류가 있으며 그 종류는 다음과 같다.

Log의 종류의미내용
Log.d()debug개발에 필요한 내용을 출력하기 위해 사용(개발자용)
Log.i()information일반적인 메세지를 전달하기 위해 사용
Log.e()error실제 에러 메시지를 출력하기 위해 사용
Log.v()verbose상세한 로그 내용을 출력하기 위해 사용
Log.w()warning에러는 아니지만 경고성 메시지를 전달하기 위해 사용



원문에서는 다음과 같이 설명한다.
stackoverflow에서 어느 개발자가 설명한 각 Log의 용도는 다음과 같다.

  • Log.e: This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're logging an error.
  • Log.w: Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a "hey, this happened, and it's weird, we should look into it."
  • Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.
  • Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.
  • Log.v: Use this when you want to go absolutely nuts with your logging. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.

And as a bonus...

  • Log.wtf: Use this when stuff goes absolutely, horribly, holy-crap wrong. You know those catch blocks where you're catching errors that you never should get...yeah, if you wanna log them use Log.wtf



profile
안드로이드 개발자

0개의 댓글