[go]로그 패키지(log package),Go Slog vs Zap 어떤것이 좋을까?

김민영·2024년 1월 14일
0

golang패키지

목록 보기
2/2
post-thumbnail

코딩 리뷰를 하다 vendor에 관련해, 고 로그 패키지를 바꾸는 경우를 보았다. 잘 쓰던 로그 패키지를 바꾸는 이유는 뭐냐고 사수에게 물었더니 패키지마다의 특성이 있어서 시스템,서비스마다 그 특성을 살릴 수 있도록 하기 위함이랬다.

그 과정에서 내가 파악한 로그패키지 slog와 zap의 차이점에 대해 노트하겠다.

Slog

Slog : https://betterstack.com/community/guides/logging/logging-in-go/

Slog는 Go 1.21에 도입된 새로운 로깅 프레임워크로, log/slog에 위치하고 있다. 이는 go 표준 라이브러리에서 고성능, 구조화된, 그리고 레벨에 따른 로깅 솔루션이 필요한 요구를 해결할 수 있다.

Slog is the new built-in logging framework that just landed in Go 1.21 , residing at log/slog. It aims to address the need for a high-performance, structured, and leveled logging solution in the Go standard library.

Zap

Zap : https://betterstack.com/community/guides/logging/go/zap/

우버의 고성능 서버에서 기록되는 느린 로깅 시간에 대한 불편함에서 발전해온 것이 Zap이다. Zerolog에 의해 채택 및 개선되었지만, 성능향상을 위해 어느정도의 유연성을 포기한 상태이다.

Zap grew out of Uber's frustration with the slow logging times recorded on their high-performance servers. It pioneered the minimal allocations approach that was eventually adopted and improved on by Zerolog, although the latter gave up some flexibility to achieve the performance gains.

실무에서 겪은 바로는, slog가 좀더 간결하고, Zap은 많은 정보가 필요할때에 사용하면 좋을듯하다.
예를 들어 vendor를 향한 로그엔 그렇게 많은 정보가 필요하지 않다고 판단 -> slog로 변경하는 등이 있다.
As i used it in a business, slog is more concise, while Zap is usful when a significant amount of information is needed. For instance, for logs releated to verdor processing, We opted for Slog since an extensive amount of information is not necessary.

profile
일본 도쿄에서 2년차 개발자로 일하고 있는 말하는 감자입니다.

0개의 댓글