slog - 가볍고 구성 가능하며 확장 가능한 Go 로깅 라이브러리
7238 단어 gologopensourceprogramming
slog는 가볍고 구성 가능하며 확장 가능한 Go 로깅 라이브러리입니다.
특징
trace debug info notice warn error fatal panic Handler Formatter의 모든 확장 지원Handler를 동시에 추가하여 다른 위치에 로그 출력 지원Formatterjson text 두 개의 로그 레코드 형식화Formatter Handlerhandler.Confighandler.Builder은 원하는 로그 핸들러console 콘솔에 로그 출력, 색상 출력 지원writer 지정된 로그로 출력 로그io.Writer file 로그를 지정된 파일로 출력, 선택적으로 버퍼 쓰기buffer simple 지정된 파일에 로그 출력, 버퍼링 없이 파일에 직접 쓰기rotate_file 지정된 파일에 로그를 출력하고 시간 및 크기별로 파일 분할을 지원하며 buffer 버퍼링된 쓰기가 기본적으로 활성화됩니다로그를 파일로 출력
buffer time 및 size로 로그 파일 분할 지원gzip를 통해 로그 파일을 압축하는 구성 지원BackupNum로 이전 로그 파일 정리 지원BackupTime Git 저장소
설치
go get github.com/gookit/slog
빠른 시작
package main
import (
"github.com/gookit/slog"
)
func main() {
slog.Trace("this is a log message")
slog.Debug("this is a log message")
slog.Info("this is a log message")
slog.Notice("this is a log message")
slog.Warn("this is a log message")
slog.Error("this is a log message")
slog.Fatal("this is a log message")
}
출력 미리보기:

파일에 기록
slog를 사용하여 로그를 파일로 출력하는 것은 매우 편리하며 여러 파일, 시간 분할 등을 지원합니다.package main
import (
"github.com/gookit/slog"
"github.com/gookit/slog/handler"
"github.com/gookit/slog/rotatefile"
)
func main() {
defer slog.MustFlush()
// DangerLevels contains: slog.PanicLevel, slog.ErrorLevel, slog.WarnLevel
h1 := handler.MustRotateFile("/tmp/logs/app_error.log", rotatefile.EveryHour,
handler.WithLogLevels(slog.DangerLevels),
)
// NormalLevels contains: slog.InfoLevel, slog.NoticeLevel, slog.DebugLevel, slog.TraceLevel
h2 := handler.MustRotateFile("/tmp/logs/app_info.log", rotatefile.EveryHour,
handler.WithLogLevels(slog.NormalLevels),
)
slog.PushHandler(h1)
slog.PushHandler(h2)
// add logs
slog.Info("info message text")
slog.Error("error message text")
}
로그 디렉토리 참조:
$ ls /tmp/logs
app_error.log
app_info.log
더 많은 사용량
More usage please see README
Reference
이 문제에 관하여(slog - 가볍고 구성 가능하며 확장 가능한 Go 로깅 라이브러리), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/inhere/slog-lightweight-configurable-extensible-go-logging-library-52h2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)