feat: replace logging with zerolog

This commit is contained in:
Manuel Rüger 2026-03-28 09:55:58 +01:00
parent 74c4a306c3
commit e160121005
19 changed files with 204 additions and 180 deletions

View File

@ -19,7 +19,7 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/vfs" "github.com/kovetskiy/mark/v16/vfs"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
const ( const (
@ -101,7 +101,7 @@ func ResolveAttachments(
} }
for i, attachment := range creating { for i, attachment := range creating {
log.Infof(nil, "creating attachment: %q", attachment.Name) log.Info().Msgf("creating attachment: %q", attachment.Name)
info, err := api.CreateAttachment( info, err := api.CreateAttachment(
page.ID, page.ID,
@ -127,7 +127,7 @@ func ResolveAttachments(
} }
for i, attachment := range updating { for i, attachment := range updating {
log.Infof(nil, "updating attachment: %q", attachment.Name) log.Info().Msgf("updating attachment: %q", attachment.Name)
info, err := api.UpdateAttachment( info, err := api.UpdateAttachment(
page.ID, page.ID,
@ -153,7 +153,7 @@ func ResolveAttachments(
} }
for i := range existing { for i := range existing {
log.Infof(nil, "keeping unmodified attachment: %q", existing[i].Name) log.Info().Msgf("keeping unmodified attachment: %q", existing[i].Name)
} }
attachments = []Attachment{} attachments = []Attachment{}
@ -260,7 +260,7 @@ func CompileAttachmentLinks(markdown []byte, attachments []Attachment) []byte {
if bytes.Contains(markdown, []byte("attachment://"+replace)) { if bytes.Contains(markdown, []byte("attachment://"+replace)) {
from := "attachment://" + replace from := "attachment://" + replace
log.Debugf(nil, "replacing legacy link: %q -> %q", from, to) log.Debug().Msgf("replacing legacy link: %q -> %q", from, to)
markdown = bytes.ReplaceAll( markdown = bytes.ReplaceAll(
markdown, markdown,
@ -274,7 +274,7 @@ func CompileAttachmentLinks(markdown []byte, attachments []Attachment) []byte {
if bytes.Contains(markdown, []byte(replace)) { if bytes.Contains(markdown, []byte(replace)) {
from := replace from := replace
log.Debugf(nil, "replacing link: %q -> %q", from, to) log.Debug().Msgf("replacing link: %q -> %q", from, to)
markdown = bytes.ReplaceAll( markdown = bytes.ReplaceAll(
markdown, markdown,
@ -286,7 +286,7 @@ func CompileAttachmentLinks(markdown []byte, attachments []Attachment) []byte {
} }
if !found { if !found {
log.Warningf(nil, "unused attachment: %s", replace) log.Warn().Msgf("unused attachment: %s", replace)
} }
} }

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"github.com/kovetskiy/mark/v16/util" "github.com/kovetskiy/mark/v16/util"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
@ -34,6 +34,6 @@ func main() {
} }
if err := cmd.Run(context.TODO(), os.Args); err != nil { if err := cmd.Run(context.TODO(), os.Args); err != nil {
log.Fatal(err) log.Fatal().Msg(err.Error())
} }
} }

View File

@ -13,9 +13,9 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/kovetskiy/gopencils" "github.com/kovetskiy/gopencils"
"github.com/kovetskiy/lorg"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog"
"github.com/rs/zerolog/log"
) )
type User struct { type User struct {
@ -96,7 +96,7 @@ type tracer struct {
} }
func (tracer *tracer) Printf(format string, args ...interface{}) { func (tracer *tracer) Printf(format string, args ...interface{}) {
log.Tracef(nil, tracer.prefix+" "+format, args...) log.Trace().Msgf(tracer.prefix+" "+format, args...)
} }
func NewAPI(baseURL string, username string, password string, insecureSkipVerify bool) *API { func NewAPI(baseURL string, username string, password string, insecureSkipVerify bool) *API {
@ -132,7 +132,7 @@ func NewAPI(baseURL string, username string, password string, insecureSkipVerify
json := gopencils.Api(baseURL+"/rpc/json-rpc/confluenceservice-v2", auth, httpClient, 3) json := gopencils.Api(baseURL+"/rpc/json-rpc/confluenceservice-v2", auth, httpClient, 3)
if log.GetLevel() == lorg.LevelTrace { if zerolog.GlobalLevel() == zerolog.TraceLevel {
rest.Logger = &tracer{"rest:"} rest.Logger = &tracer{"rest:"}
json.Logger = &tracer{"json-rpc:"} json.Logger = &tracer{"json-rpc:"}
} }

View File

@ -14,7 +14,7 @@ import (
"github.com/chromedp/chromedp" "github.com/chromedp/chromedp"
"github.com/kovetskiy/mark/v16/attachment" "github.com/kovetskiy/mark/v16/attachment"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
"oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout" "oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
@ -59,7 +59,7 @@ func ProcessD2(title string, d2Diagram []byte, scale float64) (attachment.Attach
return attachment.Attachment{}, err return attachment.Attachment{}, err
} }
log.Debugf(nil, "Rendering: %q", title) log.Debug().Msgf("Rendering: %q", title)
pngBytes, boxModel, err := convertSVGtoPNG(ctx, out, scale) pngBytes, boxModel, err := convertSVGtoPNG(ctx, out, scale)
if err != nil { if err != nil {
return attachment.Attachment{}, err return attachment.Attachment{}, err
@ -73,7 +73,7 @@ func ProcessD2(title string, d2Diagram []byte, scale float64) (attachment.Attach
checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Bytes)) checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Bytes))
log.Debugf(nil, "Checksum: %q -> %s", title, checkSum) log.Debug().Msgf("Checksum: %q -> %s", title, checkSum)
if err != nil { if err != nil {
return attachment.Attachment{}, err return attachment.Attachment{}, err

7
go.mod
View File

@ -8,9 +8,8 @@ require (
github.com/chromedp/chromedp v0.15.1 github.com/chromedp/chromedp v0.15.1
github.com/dreampuf/mermaid.go v0.0.40 github.com/dreampuf/mermaid.go v0.0.40
github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a
github.com/kovetskiy/lorg v1.2.1-0.20240830111423-ba4fe8b6f7c4
github.com/reconquest/karma-go v1.5.0 github.com/reconquest/karma-go v1.5.0
github.com/reconquest/pkg v1.3.1-0.20240901105413-68c2adbf2b64 github.com/rs/zerolog v1.35.0
github.com/stefanfritsch/goldmark-admonitions v1.1.1 github.com/stefanfritsch/goldmark-admonitions v1.1.1
github.com/stretchr/testify v1.11.1 github.com/stretchr/testify v1.11.1
github.com/urfave/cli-altsrc/v3 v3.1.0 github.com/urfave/cli-altsrc/v3 v3.1.0
@ -41,13 +40,13 @@ require (
github.com/google/pprof v0.0.0-20240927180334-d43a67379298 // indirect github.com/google/pprof v0.0.0-20240927180334-d43a67379298 // indirect
github.com/kr/pretty v0.3.1 // indirect github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mazznoer/csscolorparser v0.1.5 // indirect github.com/mazznoer/csscolorparser v0.1.5 // indirect
github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785 // indirect github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/reconquest/cog v0.0.0-20240830113510-c7ba12d0beeb // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/zazab/zhash v0.0.0-20221031090444-2b0d50417446 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/image v0.20.0 // indirect golang.org/x/image v0.20.0 // indirect
golang.org/x/net v0.44.0 // indirect golang.org/x/net v0.44.0 // indirect

14
go.sum
View File

@ -51,8 +51,6 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a h1:OPt6gCghZXQ/WZpT6EhGkA7v+YMAYzcCb8SPQWmsb/8= github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a h1:OPt6gCghZXQ/WZpT6EhGkA7v+YMAYzcCb8SPQWmsb/8=
github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a/go.mod h1:gRW37oDEg9LzOHApv31YzxKBICcCmPtDogaImsxZ6xc= github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a/go.mod h1:gRW37oDEg9LzOHApv31YzxKBICcCmPtDogaImsxZ6xc=
github.com/kovetskiy/lorg v1.2.1-0.20240830111423-ba4fe8b6f7c4 h1:2eV8tF1u58dqRJMlFUD/Df26BxcIlGVy71rZHN+aNoI=
github.com/kovetskiy/lorg v1.2.1-0.20240830111423-ba4fe8b6f7c4/go.mod h1:p1RuSvyflTF/G4ubeATGurCRKWkULOrN/4PUAEFRq0s=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@ -64,6 +62,10 @@ github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kUL
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs= github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mazznoer/csscolorparser v0.1.5 h1:Wr4uNIE+pHWN3TqZn2SGpA2nLRG064gB7WdSfSS5cz4= github.com/mazznoer/csscolorparser v0.1.5 h1:Wr4uNIE+pHWN3TqZn2SGpA2nLRG064gB7WdSfSS5cz4=
github.com/mazznoer/csscolorparser v0.1.5/go.mod h1:OQRVvgCyHDCAquR1YWfSwwaDcM0LhnSffGnlbOew/3I= github.com/mazznoer/csscolorparser v0.1.5/go.mod h1:OQRVvgCyHDCAquR1YWfSwwaDcM0LhnSffGnlbOew/3I=
github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785 h1:J1//5K/6QF10cZ59zLcVNFGmBfiSrH8Cho/lNrViK9s= github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785 h1:J1//5K/6QF10cZ59zLcVNFGmBfiSrH8Cho/lNrViK9s=
@ -71,17 +73,15 @@ github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785/go.mod h1:nZgzb
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/reconquest/cog v0.0.0-20240830113510-c7ba12d0beeb h1:hJ1ExqE2lTMgTRmjmSiC2hm+sMXCCjjbyiGo3irbEW8=
github.com/reconquest/cog v0.0.0-20240830113510-c7ba12d0beeb/go.mod h1:n+lvvNLeoQmYVvYTFGCtLvoyD9Wz46RO3yCk6GKyZ/4=
github.com/reconquest/karma-go v1.5.0 h1:Chn4LtauwnvKfz13ZbmGNrRLKO1NciExHQSOBOsQqt4= github.com/reconquest/karma-go v1.5.0 h1:Chn4LtauwnvKfz13ZbmGNrRLKO1NciExHQSOBOsQqt4=
github.com/reconquest/karma-go v1.5.0/go.mod h1:52XRXXa2ec/VNrlCirwasdJfNmjI1O87q098gmqILh0= github.com/reconquest/karma-go v1.5.0/go.mod h1:52XRXXa2ec/VNrlCirwasdJfNmjI1O87q098gmqILh0=
github.com/reconquest/pkg v1.3.1-0.20240901105413-68c2adbf2b64 h1:OBNLiZay5PYLmGRXGIMEgWSIgbSjOj8nHZxqwLbSsF4=
github.com/reconquest/pkg v1.3.1-0.20240901105413-68c2adbf2b64/go.mod h1:r1Z1JNh3in9xLWbhv5u7cdox9vvGFjlKp89VI10Jrdo=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/zerolog v1.35.0 h1:VD0ykx7HMiMJytqINBsKcbLS+BJ4WYjz+05us+LRTdI=
github.com/rs/zerolog v1.35.0/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw=
github.com/stefanfritsch/goldmark-admonitions v1.1.1 h1:SncsICdQrIYYaq02Ta+zyc9gNmMfYqQH2qwLSCJYxA4= github.com/stefanfritsch/goldmark-admonitions v1.1.1 h1:SncsICdQrIYYaq02Ta+zyc9gNmMfYqQH2qwLSCJYxA4=
github.com/stefanfritsch/goldmark-admonitions v1.1.1/go.mod h1:cOZK5O0gE6eWfpxTdjGUmeONW2IL9j3Zujv3KlZWlLo= github.com/stefanfritsch/goldmark-admonitions v1.1.1/go.mod h1:cOZK5O0gE6eWfpxTdjGUmeONW2IL9j3Zujv3KlZWlLo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
@ -95,8 +95,6 @@ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3i
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.8.2 h1:kEGpgqJXdgbkhcOgBxkC0X0PmoPG1ZyoZ117rDVp4zE= github.com/yuin/goldmark v1.8.2 h1:kEGpgqJXdgbkhcOgBxkC0X0PmoPG1ZyoZ117rDVp4zE=
github.com/yuin/goldmark v1.8.2/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= github.com/yuin/goldmark v1.8.2/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
github.com/zazab/zhash v0.0.0-20221031090444-2b0d50417446 h1:75pcOSsb40+ub185cJI7g5uykl9Uu76rD5ONzK/4s40=
github.com/zazab/zhash v0.0.0-20221031090444-2b0d50417446/go.mod h1:NtepZ8TEXErPsmQDMUoN72f8aIy4+xNinSJ3f1giess=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=

View File

@ -12,7 +12,7 @@ import (
"go.yaml.in/yaml/v3" "go.yaml.in/yaml/v3"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
// <!-- Include: <template path> // <!-- Include: <template path>
@ -146,7 +146,7 @@ func ProcessIncludes(
return spec return spec
} }
log.Tracef(vardump(facts, data), "including template %q", path) log.Trace().Interface("vardump", vardump(facts, data)).Msgf("including template %q", path)
templates, err = LoadTemplate(base, includePath, path, left, right, templates) templates, err = LoadTemplate(base, includePath, path, left, right, templates)
if err != nil { if err != nil {

View File

@ -8,8 +8,7 @@ import (
"text/template" "text/template"
"github.com/kovetskiy/mark/v16/includes" "github.com/kovetskiy/mark/v16/includes"
"github.com/reconquest/karma-go" "github.com/rs/zerolog/log"
"github.com/reconquest/pkg/log"
"go.yaml.in/yaml/v3" "go.yaml.in/yaml/v3"
) )
@ -190,11 +189,9 @@ func ExtractMacros(
macro.Config = config macro.Config = config
log.Tracef( log.Trace().
facts.Describe("config", macro.Config), Interface("vardump", facts.Describe("config", macro.Config)).
"loaded macro %q", Msgf("loaded macro %q", expr)
expr,
)
macros = append(macros, macro) macros = append(macros, macro)

41
mark.go
View File

@ -25,7 +25,7 @@ import (
"github.com/kovetskiy/mark/v16/types" "github.com/kovetskiy/mark/v16/types"
"github.com/kovetskiy/mark/v16/vfs" "github.com/kovetskiy/mark/v16/vfs"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
// Config holds all configuration options for running Mark. // Config holds all configuration options for running Mark.
@ -96,7 +96,7 @@ func Run(config Config) error {
if len(files) == 0 { if len(files) == 0 {
msg := "no files matched" msg := "no files matched"
if config.CI { if config.CI {
log.Warning(msg) log.Warn().Msg(msg)
} else { } else {
return fmt.Errorf("%s", msg) return fmt.Errorf("%s", msg)
} }
@ -104,12 +104,12 @@ func Run(config Config) error {
var hasErrors bool var hasErrors bool
for _, file := range files { for _, file := range files {
log.Infof(nil, "processing %s", file) log.Info().Msgf("processing %s", file)
target, err := ProcessFile(file, api, config) target, err := ProcessFile(file, api, config)
if err != nil { if err != nil {
if config.ContinueOnError { if config.ContinueOnError {
log.Errorf(err, "processing %s", file) log.Error().Err(err).Msgf("processing %s", file)
hasErrors = true hasErrors = true
continue continue
} }
@ -117,7 +117,7 @@ func Run(config Config) error {
} }
if target != nil { if target != nil {
log.Infof(nil, "page successfully updated: %s", api.BaseURL+target.Links.Full) log.Info().Msgf("page successfully updated: %s", api.BaseURL+target.Links.Full)
if _, err := fmt.Fprintln(config.output(), api.BaseURL+target.Links.Full); err != nil { if _, err := fmt.Fprintln(config.output(), api.BaseURL+target.Links.Full); err != nil {
return err return err
} }
@ -156,7 +156,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
} }
if config.PageID != "" && meta != nil { if config.PageID != "" && meta != nil {
log.Warning( log.Warn().Msg(
`specified file contains metadata, ` + `specified file contains metadata, ` +
`but it will be ignored due specified command line URL`, `but it will be ignored due specified command line URL`,
) )
@ -255,7 +255,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
if config.CompileOnly || config.DryRun { if config.CompileOnly || config.DryRun {
if config.DropH1 { if config.DropH1 {
log.Info("the leading H1 heading will be excluded from the Confluence output") log.Info().Msg("the leading H1 heading will be excluded from the Confluence output")
} }
imageAlign, err := getImageAlign(config.ImageAlign, meta) imageAlign, err := getImageAlign(config.ImageAlign, meta)
@ -335,7 +335,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
markdown = attachment.CompileAttachmentLinks(markdown, attaches) markdown = attachment.CompileAttachmentLinks(markdown, attaches)
if config.DropH1 { if config.DropH1 {
log.Info("the leading H1 heading will be excluded from the Confluence output") log.Info().Msg("the leading H1 heading will be excluded from the Confluence output")
} }
imageAlign, err := getImageAlign(config.ImageAlign, meta) imageAlign, err := getImageAlign(config.ImageAlign, meta)
@ -399,13 +399,13 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
if config.ChangesOnly { if config.ChangesOnly {
contentHash := sha1Hash(html) contentHash := sha1Hash(html)
log.Debugf(nil, "content hash: %s", contentHash) log.Debug().Msgf("content hash: %s", contentHash)
re := regexp.MustCompile(`\[v([a-f0-9]{40})]$`) re := regexp.MustCompile(`\[v([a-f0-9]{40})]$`)
if matches := re.FindStringSubmatch(target.Version.Message); len(matches) > 1 { if matches := re.FindStringSubmatch(target.Version.Message); len(matches) > 1 {
log.Debugf(nil, "previous content hash: %s", matches[1]) log.Debug().Msgf("previous content hash: %s", matches[1])
if matches[1] == contentHash { if matches[1] == contentHash {
log.Infof(nil, "page %q is already up to date", target.Title) log.Info().Msgf("page %q is already up to date", target.Title)
shouldUpdatePage = false shouldUpdatePage = false
} }
} }
@ -436,8 +436,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
} }
if config.EditLock { if config.EditLock {
log.Infof( log.Info().Msgf(
nil,
`edit locked on page %q by user %q to prevent manual edits`, `edit locked on page %q by user %q to prevent manual edits`,
target.Title, target.Title,
config.Username, config.Username,
@ -456,18 +455,18 @@ func updateLabels(api *confluence.API, target *confluence.PageInfo, metaLabels [
return err return err
} }
log.Debug("Page Labels:") log.Debug().Msg("Page Labels:")
log.Debug(labelInfo.Labels) log.Debug().Interface("labels", labelInfo.Labels).Send()
log.Debug("Meta Labels:") log.Debug().Msg("Meta Labels:")
log.Debug(metaLabels) log.Debug().Interface("labels", metaLabels).Send()
delLabels := determineLabelsToRemove(labelInfo, metaLabels) delLabels := determineLabelsToRemove(labelInfo, metaLabels)
log.Debug("Del Labels:") log.Debug().Msg("Del Labels:")
log.Debug(delLabels) log.Debug().Interface("labels", delLabels).Send()
addLabels := determineLabelsToAdd(metaLabels, labelInfo) addLabels := determineLabelsToAdd(metaLabels, labelInfo)
log.Debug("Add Labels:") log.Debug().Msg("Add Labels:")
log.Debug(addLabels) log.Debug().Interface("labels", addLabels).Send()
if len(addLabels) > 0 { if len(addLabels) > 0 {
if _, err = api.AddPageLabels(target, addLabels); err != nil { if _, err = api.AddPageLabels(target, addLabels); err != nil {

View File

@ -9,7 +9,7 @@ import (
crenderer "github.com/kovetskiy/mark/v16/renderer" crenderer "github.com/kovetskiy/mark/v16/renderer"
"github.com/kovetskiy/mark/v16/stdlib" "github.com/kovetskiy/mark/v16/stdlib"
"github.com/kovetskiy/mark/v16/types" "github.com/kovetskiy/mark/v16/types"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
mkDocsParser "github.com/stefanfritsch/goldmark-admonitions" mkDocsParser "github.com/stefanfritsch/goldmark-admonitions"
"github.com/yuin/goldmark" "github.com/yuin/goldmark"
@ -91,7 +91,7 @@ func (c *ConfluenceExtension) Extend(m goldmark.Markdown) {
} }
func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib, path string, cfg types.MarkConfig) (string, []attachment.Attachment, error) { func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib, path string, cfg types.MarkConfig) (string, []attachment.Attachment, error) {
log.Tracef(nil, "rendering markdown:\n%s", string(markdown)) log.Trace().Msgf("rendering markdown:\n%s", string(markdown))
confluenceExtension := NewConfluenceExtension(stdlib, path, cfg) confluenceExtension := NewConfluenceExtension(stdlib, path, cfg)
@ -124,7 +124,7 @@ func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib, path string, cfg types
html := buf.Bytes() html := buf.Bytes()
log.Tracef(nil, "rendered markdown to html:\n%s", string(html)) log.Trace().Msgf("rendered markdown to html:\n%s", string(html))
return string(html), confluenceExtension.Attachments, nil return string(html), confluenceExtension.Attachments, nil
} }

View File

@ -10,7 +10,7 @@ import (
mermaid "github.com/dreampuf/mermaid.go" mermaid "github.com/dreampuf/mermaid.go"
"github.com/kovetskiy/mark/v16/attachment" "github.com/kovetskiy/mark/v16/attachment"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
var renderTimeout = 120 * time.Second var renderTimeout = 120 * time.Second
@ -19,14 +19,14 @@ func ProcessMermaidLocally(title string, mermaidDiagram []byte, scale float64) (
ctx, cancel := context.WithTimeout(context.TODO(), renderTimeout) ctx, cancel := context.WithTimeout(context.TODO(), renderTimeout)
defer cancel() defer cancel()
log.Debugf(nil, "Setting up Mermaid renderer: %q", title) log.Debug().Msgf("Setting up Mermaid renderer: %q", title)
renderer, err := mermaid.NewRenderEngine(ctx) renderer, err := mermaid.NewRenderEngine(ctx)
if err != nil { if err != nil {
return attachment.Attachment{}, err return attachment.Attachment{}, err
} }
log.Debugf(nil, "Rendering: %q", title) log.Debug().Msgf("Rendering: %q", title)
pngBytes, boxModel, err := renderer.RenderAsScaledPng(string(mermaidDiagram), scale) pngBytes, boxModel, err := renderer.RenderAsScaledPng(string(mermaidDiagram), scale)
if err != nil { if err != nil {
return attachment.Attachment{}, err return attachment.Attachment{}, err
@ -39,7 +39,7 @@ func ProcessMermaidLocally(title string, mermaidDiagram []byte, scale float64) (
mermaidBytes := append(mermaidDiagram, scaleAsBytes...) mermaidBytes := append(mermaidDiagram, scaleAsBytes...)
checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidBytes)) checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidBytes))
log.Debugf(nil, "Checksum: %q -> %s", title, checkSum) log.Debug().Msgf("Checksum: %q -> %s", title, checkSum)
if err != nil { if err != nil {
return attachment.Attachment{}, err return attachment.Attachment{}, err

View File

@ -9,7 +9,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -132,12 +132,9 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi
meta.ImageAlign = strings.ToLower(strings.TrimSpace(value)) meta.ImageAlign = strings.ToLower(strings.TrimSpace(value))
default: default:
log.Errorf( log.Error().
nil, Err(nil).
`encountered unknown header %q line: %#v`, Msgf(`encountered unknown header %q line: %#v`, header, line)
header,
line,
)
continue continue
} }
@ -193,11 +190,7 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi
pathHash := sha256.Sum256([]byte(path)) pathHash := sha256.Sum256([]byte(path))
// postfix is an 8-character hexadecimal string representation of the first 4 out of 32 bytes of the hash // postfix is an 8-character hexadecimal string representation of the first 4 out of 32 bytes of the hash
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4]) meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4])
log.Debugf( log.Debug().Msgf("appended hash to page title: %s", meta.Title)
nil,
"appended hash to page title: %s",
meta.Title,
)
} }
// Remove trailing spaces from title // Remove trailing spaces from title

View File

@ -6,7 +6,7 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
func EnsureAncestry( func EnsureAncestry(
@ -33,7 +33,7 @@ func EnsureAncestry(
break break
} }
log.Debugf(nil, "parent page %q exists: %s", title, page.Links.Full) log.Debug().Msgf("parent page %q exists: %s", title, page.Links.Full)
rest = ancestry[i:] rest = ancestry[i:]
parent = page parent = page
@ -57,8 +57,8 @@ func EnsureAncestry(
return parent, nil return parent, nil
} }
log.Debugf( log.Debug().
nil, Msgf(
"empty pages under %q to be created: %s", "empty pages under %q to be created: %s",
parent.Title, parent.Title,
strings.Join(rest, ` > `), strings.Join(rest, ` > `),
@ -78,8 +78,8 @@ func EnsureAncestry(
parent = page parent = page
} }
} else { } else {
log.Infof( log.Info().
nil, Msgf(
"skipping page creation due to enabled dry-run mode, "+ "skipping page creation due to enabled dry-run mode, "+
"need to create %d pages: %v", "need to create %d pages: %v",
len(rest), len(rest),
@ -116,7 +116,7 @@ func ValidateAncestry(
} }
if page.ID == homepage.ID { if page.ID == homepage.ID {
log.Debugf(nil, "page is homepage for space %q", space) log.Debug().Msgf("page is homepage for space %q", space)
isHomepage = true isHomepage = true
} else { } else {
return nil, fmt.Errorf(`page %q has no parents`, page.Title) return nil, fmt.Errorf(`page %q has no parents`, page.Title)

View File

@ -15,7 +15,7 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/metadata" "github.com/kovetskiy/mark/v16/metadata"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
type LinkSubstitution struct { type LinkSubstitution struct {
@ -51,8 +51,8 @@ func ResolveRelativeLinks(
links := []LinkSubstitution{} links := []LinkSubstitution{}
for _, match := range matches { for _, match := range matches {
log.Tracef( log.Trace().
nil, Msgf(
"found a relative link: full=%s filename=%s hash=%s", "found a relative link: full=%s filename=%s hash=%s",
match.full, match.full,
match.filename, match.filename,
@ -91,7 +91,7 @@ func resolveLink(
if len(link.filename) > 0 { if len(link.filename) > 0 {
filepath := filepath.Join(base, link.filename) filepath := filepath.Join(base, link.filename)
log.Tracef(nil, "filepath: %s", filepath) log.Trace().Msgf("filepath: %s", filepath)
stat, err := os.Stat(filepath) stat, err := os.Stat(filepath)
if err != nil { if err != nil {
return "", nil return "", nil
@ -109,7 +109,7 @@ func resolveLink(
contentType := http.DetectContentType(linkContents) contentType := http.DetectContentType(linkContents)
// Check if the MIME type starts with "text/" // Check if the MIME type starts with "text/"
if !strings.HasPrefix(contentType, "text/") { if !strings.HasPrefix(contentType, "text/") {
log.Debugf(nil, "Ignoring link to file %q: detected content type %v", filepath, contentType) log.Debug().Msgf("Ignoring link to file %q: detected content type %v", filepath, contentType)
return "", nil return "", nil
} }
@ -123,8 +123,9 @@ func resolveLink(
// not markdown or have mark required metadata // not markdown or have mark required metadata
linkMeta, _, err := metadata.ExtractMeta(linkContents, spaceForLinks, titleFromH1, titleFromFilename, filepath, parents, titleAppendGeneratedHash, "") linkMeta, _, err := metadata.ExtractMeta(linkContents, spaceForLinks, titleFromH1, titleFromFilename, filepath, parents, titleAppendGeneratedHash, "")
if err != nil { if err != nil {
log.Errorf( log.Error().
err, Err(err).
Msgf(
"unable to extract metadata from %q; ignoring the relative link", "unable to extract metadata from %q; ignoring the relative link",
filepath, filepath,
) )
@ -136,8 +137,8 @@ func resolveLink(
return "", nil return "", nil
} }
log.Tracef( log.Trace().
nil, Msgf(
"extracted metadata: space=%s title=%s", "extracted metadata: space=%s title=%s",
linkMeta.Space, linkMeta.Space,
linkMeta.Title, linkMeta.Title,
@ -172,7 +173,7 @@ func SubstituteLinks(markdown []byte, links []LinkSubstitution) []byte {
continue continue
} }
log.Tracef(nil, "substitute link: %q -> %q", link.From, link.To) log.Trace().Msgf("substitute link: %q -> %q", link.From, link.To)
markdown = bytes.ReplaceAll( markdown = bytes.ReplaceAll(
markdown, markdown,

View File

@ -6,7 +6,7 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/metadata" "github.com/kovetskiy/mark/v16/metadata"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
) )
func ResolvePage( func ResolvePage(
@ -27,8 +27,8 @@ func ResolvePage(
} }
if meta.Type == "blogpost" { if meta.Type == "blogpost" {
log.Infof( log.Info().
nil, Msgf(
"blog post will be stored as: %s", "blog post will be stored as: %s",
meta.Title, meta.Title,
) )
@ -69,8 +69,8 @@ func ResolvePage(
} }
if page == nil { if page == nil {
log.Warningf( log.Warn().
nil, Msgf(
"page %q is not found ", "page %q is not found ",
ancestry[len(ancestry)-1], ancestry[len(ancestry)-1],
) )
@ -79,8 +79,8 @@ func ResolvePage(
path := meta.Parents path := meta.Parents
path = append(path, meta.Title) path = append(path, meta.Title)
log.Debugf( log.Debug().
nil, Msgf(
"resolving page path: ??? > %s", "resolving page path: ??? > %s",
strings.Join(path, ` > `), strings.Join(path, ` > `),
) )
@ -107,8 +107,7 @@ func ResolvePage(
titles = append(titles, parent.Title) titles = append(titles, parent.Title)
log.Infof( log.Info().Msgf(
nil,
"page will be stored under path: %s > %s", "page will be stored under path: %s > %s",
strings.Join(titles, ` > `), strings.Join(titles, ` > `),
meta.Title, meta.Title,

View File

@ -6,7 +6,7 @@ import (
"text/template" "text/template"
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog/log"
"github.com/reconquest/karma-go" "github.com/reconquest/karma-go"
) )
@ -42,7 +42,7 @@ func templates(api *confluence.API) (*template.Template, error) {
} }
user, err := api.GetUserByName(name) user, err := api.GetUserByName(name)
if err != nil { if err != nil {
log.Error(err) log.Error().Err(err).Send()
} }
return user return user

View File

@ -7,9 +7,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/kovetskiy/lorg" "github.com/rs/zerolog"
"github.com/rs/zerolog/log"
mark "github.com/kovetskiy/mark/v16" mark "github.com/kovetskiy/mark/v16"
"github.com/reconquest/pkg/log"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
@ -18,14 +18,54 @@ func RunMark(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
if cmd.String("color") == "never" { zerolog.TimeFieldFormat = "2006-01-02 15:04:05.000"
log.GetLogger().SetFormat(
lorg.NewFormat( output := zerolog.ConsoleWriter{
`${time:2006-01-02 15:04:05.000} ${level:%s:left:true} ${prefix}%s`, Out: os.Stderr,
), TimeFormat: "2006-01-02 15:04:05.000",
) FormatLevel: func(i interface{}) string {
log.GetLogger().SetOutput(os.Stderr) var l string
if ll, ok := i.(string); ok {
switch ll {
case "trace":
l = "TRACE"
case "debug":
l = "DEBUG"
case "info":
l = "INFO"
case "warn":
l = "WARNING"
case "error":
l = "ERROR"
case "fatal":
l = "FATAL"
case "panic":
l = "PANIC"
default:
l = strings.ToUpper(ll)
} }
} else {
l = strings.ToUpper(fmt.Sprintf("%s", i))
}
return l
},
FormatFieldName: func(i interface{}) string {
return ""
},
FormatFieldValue: func(i interface{}) string {
return fmt.Sprintf("%s", i)
},
FormatErrFieldName: func(i interface{}) string {
return ""
},
FormatErrFieldValue: func(i interface{}) string {
return fmt.Sprintf("%s", i)
},
}
if cmd.String("color") == "never" {
output.NoColor = true
}
log.Logger = zerolog.New(output).With().Timestamp().Logger()
creds, err := GetCredentials( creds, err := GetCredentials(
cmd.String("username"), cmd.String("username"),
@ -38,13 +78,13 @@ func RunMark(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
log.Debug("config:") log.Debug().Msg("config:")
for _, f := range cmd.Flags { for _, f := range cmd.Flags {
flag := f.Names() flag := f.Names()
if flag[0] == "password" { if flag[0] == "password" {
log.Debugf(nil, "%20s: %v", flag[0], "******") log.Debug().Msgf("%20s: %v", flag[0], "******")
} else { } else {
log.Debugf(nil, "%20s: %v", flag[0], cmd.Value(flag[0])) log.Debug().Msgf("%20s: %v", flag[0], cmd.Value(flag[0]))
} }
} }
@ -93,7 +133,7 @@ func RunMark(ctx context.Context, cmd *cli.Command) error {
func ConfigFilePath() string { func ConfigFilePath() string {
fp, err := os.UserConfigDir() fp, err := os.UserConfigDir()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal().Err(err).Send()
} }
return filepath.Join(fp, "mark.toml") return filepath.Join(fp, "mark.toml")
} }
@ -101,18 +141,18 @@ func ConfigFilePath() string {
func SetLogLevel(cmd *cli.Command) error { func SetLogLevel(cmd *cli.Command) error {
logLevel := cmd.String("log-level") logLevel := cmd.String("log-level")
switch strings.ToUpper(logLevel) { switch strings.ToUpper(logLevel) {
case lorg.LevelTrace.String(): case "TRACE":
log.SetLevel(lorg.LevelTrace) zerolog.SetGlobalLevel(zerolog.TraceLevel)
case lorg.LevelDebug.String(): case "DEBUG":
log.SetLevel(lorg.LevelDebug) zerolog.SetGlobalLevel(zerolog.DebugLevel)
case lorg.LevelInfo.String(): case "INFO":
log.SetLevel(lorg.LevelInfo) zerolog.SetGlobalLevel(zerolog.InfoLevel)
case lorg.LevelWarning.String(): case "WARNING":
log.SetLevel(lorg.LevelWarning) zerolog.SetGlobalLevel(zerolog.WarnLevel)
case lorg.LevelError.String(): case "ERROR":
log.SetLevel(lorg.LevelError) zerolog.SetGlobalLevel(zerolog.ErrorLevel)
case lorg.LevelFatal.String(): case "FATAL":
log.SetLevel(lorg.LevelFatal) zerolog.SetGlobalLevel(zerolog.FatalLevel)
default: default:
return fmt.Errorf("unknown log level: %s", logLevel) return fmt.Errorf("unknown log level: %s", logLevel)
} }

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"github.com/reconquest/pkg/log" "github.com/rs/zerolog"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
@ -83,22 +83,22 @@ func Test_setLogLevel(t *testing.T) {
} }
tests := map[string]struct { tests := map[string]struct {
args args args args
want log.Level want zerolog.Level
expectedErr string expectedErr string
}{ }{
"invalid": {args: args{lvl: "INVALID"}, want: log.LevelInfo, expectedErr: "unknown log level: INVALID"}, "invalid": {args: args{lvl: "INVALID"}, want: zerolog.InfoLevel, expectedErr: "unknown log level: INVALID"},
"empty": {args: args{lvl: ""}, want: log.LevelInfo, expectedErr: "unknown log level: "}, "empty": {args: args{lvl: ""}, want: zerolog.InfoLevel, expectedErr: "unknown log level: "},
"info": {args: args{lvl: log.LevelInfo.String()}, want: log.LevelInfo}, "info": {args: args{lvl: "INFO"}, want: zerolog.InfoLevel},
"debug": {args: args{lvl: log.LevelDebug.String()}, want: log.LevelDebug}, "debug": {args: args{lvl: "DEBUG"}, want: zerolog.DebugLevel},
"trace": {args: args{lvl: log.LevelTrace.String()}, want: log.LevelTrace}, "trace": {args: args{lvl: "TRACE"}, want: zerolog.TraceLevel},
"warning": {args: args{lvl: log.LevelWarning.String()}, want: log.LevelWarning}, "warning": {args: args{lvl: "WARNING"}, want: zerolog.WarnLevel},
"error": {args: args{lvl: log.LevelError.String()}, want: log.LevelError}, "error": {args: args{lvl: "ERROR"}, want: zerolog.ErrorLevel},
"fatal": {args: args{lvl: log.LevelFatal.String()}, want: log.LevelFatal}, "fatal": {args: args{lvl: "FATAL"}, want: zerolog.FatalLevel},
} }
for name, tt := range tests { for name, tt := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
prev := log.GetLevel() prev := zerolog.GlobalLevel()
t.Cleanup(func() { log.SetLevel(prev) }) t.Cleanup(func() { zerolog.SetGlobalLevel(prev) })
cmd := &cli.Command{ cmd := &cli.Command{
Name: "test", Name: "test",
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -114,7 +114,7 @@ func Test_setLogLevel(t *testing.T) {
assert.EqualError(t, err, tt.expectedErr) assert.EqualError(t, err, tt.expectedErr)
} else { } else {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, tt.want, log.GetLevel()) assert.Equal(t, tt.want, zerolog.GlobalLevel())
} }
}) })
} }

View File

@ -1,9 +1,7 @@
package util package util
import ( import (
"fmt" "github.com/rs/zerolog/log"
"github.com/reconquest/pkg/log"
) )
type FatalErrorHandler struct { type FatalErrorHandler struct {
@ -20,15 +18,15 @@ func (h *FatalErrorHandler) Handle(err error, format string, args ...interface{}
if err == nil { if err == nil {
if h.ContinueOnError { if h.ContinueOnError {
log.Error(fmt.Sprintf(format, args...)) log.Error().Msgf(format, args...)
return return
} }
log.Fatal(fmt.Sprintf(format, args...)) log.Fatal().Msgf(format, args...)
} }
if h.ContinueOnError { if h.ContinueOnError {
log.Errorf(err, format, args...) log.Error().Err(err).Msgf(format, args...)
return return
} }
log.Fatalf(err, format, args...) log.Fatal().Err(err).Msgf(format, args...)
} }