로깅은 개발자가 자바 애플리케이션 수준에서 예외 사항을 기록할 때 사용하는 툴이다. 로그는
메트릭의 보완재로 활용할 수 있으며 부가 콘텍스트 정보를 담고 있어 활용 가치가 높다. 로그
기록 형식은 일반 텍스트,
JSON
및
XML
, 바이너리 등 크게 세가지로 나뉜다.
자바 언어는 내장 로그 라이브러리가 있다. 그러나
SLF4J
Simple
Logging
Facade
for
Java
38
, 아파치
Log4j
2
39
등의 로깅 프레임워크를 사용하면 더 편리하게 로그를 다룰 수 있다. 다음은 로그를
기록하고 처리할 때 참고할 만한 권장 사항들이다.
●
로깅은 보수적으로 접근해야 한다. 전체 시스템 중 로깅 범위를 한정하고 특정 기능의 세부 정보만 기록
한다.
●
자신뿐만 아니라 향후 동료들이 문제를 해결할 때 참고하도록 로그 메시지에 의미 있는 정보를 기록
한다.
●
로그 수준
level
을 정확하게 구별한다. 세분화된 정보에서 직관을 얻기 위한
TRACE
, 문제 해결에 필요한
정보가 담긴
DEBUG
, 일반적인 정보를 나타내는
INFO
, 조치할 지점을 가리키는
WARN
과
ERROR
등을 상황에 맞게 선택한다.
●
적합한 로그 수준이 활성화됐는지 확인하고 가드
guard
구문이나 또는 람다 표현식으로 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.