- commit
- 95810a1
- parent
- 4cb9cc5
- author
- Eric Bower
- date
- 2023-08-09 13:29:22 +0000 UTC
added logger
M
go.mod
+2,
-1
1@@ -7,11 +7,12 @@ require (
2 github.com/dustin/go-humanize v1.0.0
3 github.com/gogs/git-module v1.6.0
4 github.com/mergestat/timediff v0.0.3
5+ go.uber.org/zap v1.25.0
6 )
7
8 require (
9 github.com/dlclark/regexp2 v1.7.0 // indirect
10 github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 // indirect
11- github.com/stretchr/testify v1.8.0 // indirect
12+ go.uber.org/multierr v1.10.0 // indirect
13 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
14 )
M
go.sum
+7,
-5
1@@ -1,5 +1,6 @@
2 github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
3 github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
4+github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
5 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8@@ -17,12 +18,14 @@ github.com/mergestat/timediff v0.0.3/go.mod h1:yvMUaRu2oetc+9IbPLYBJviz6sA7xz8OX
9 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
12-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
13 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
14 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
15-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16-github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
17-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
18+github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
19+go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
20+go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
21+go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
22+go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
23+go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
24 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
25 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
26 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27@@ -30,4 +33,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
28 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
29 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
30 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
31-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
M
main.go
+23,
-6
1@@ -21,6 +21,7 @@ import (
2 "github.com/dustin/go-humanize"
3 git "github.com/gogs/git-module"
4 "github.com/mergestat/timediff"
5+ "go.uber.org/zap"
6 )
7
8 //go:embed html/*.tmpl
9@@ -48,8 +49,6 @@ type Config struct {
10 // We offer a way to disable showing the latest commit in the output
11 // for those who want a faster build time
12 HideTreeLastCommit bool
13- // chroma style
14- Theme *chroma.Style
15
16 // user-defined urls
17 HomeUrl template.URL
18@@ -60,6 +59,10 @@ type Config struct {
19 Cache map[string]bool
20 // pretty name for the repo
21 RepoName string
22+ // logger
23+ Logger *zap.SugaredLogger
24+ // chroma style
25+ Theme *chroma.Style
26 }
27
28 // revision data
29@@ -307,7 +310,7 @@ func (c *Config) writeHtml(writeData *WriteData) {
30 bail(err)
31
32 fp := filepath.Join(dir, writeData.Filename)
33- fmt.Printf("writing (%s)\n", fp)
34+ c.Logger.Infof("writing (%s)", fp)
35
36 w, err := os.OpenFile(fp, os.O_WRONLY|os.O_CREATE, 0755)
37 bail(err)
38@@ -682,7 +685,7 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
39 var lastCommits []*git.Commit
40 // `git rev-list` is pretty expensive here, so we have a flag to disable
41 if pageData.Repo.HideTreeLastCommit {
42- fmt.Println("skipping finding last commit for each file")
43+ c.Logger.Info("skipping finding last commit for each file")
44 } else {
45 lastCommits, err = repo.RevList([]string{pageData.RevData.ID}, git.RevListOptions{
46 Path: entry.Path,
47@@ -708,7 +711,11 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
48 ))
49 }
50
51- fmt.Printf("compilation complete (%s) branch (%s)\n", c.RepoName, pageData.RevData.RevName)
52+ c.Logger.Infof(
53+ "compilation complete (%s) branch (%s)",
54+ c.RepoName,
55+ pageData.RevData.RevName,
56+ )
57
58 c.writeLog(pageData, logs)
59 c.writeLogDiffs(repo, pageData, logs)
60@@ -745,6 +752,14 @@ func main() {
61
62 theme := styles.Get(*themeFlag)
63
64+ lg, err := zap.NewProduction()
65+ if err != nil {
66+ bail(err)
67+ }
68+
69+ logger := lg.Sugar()
70+
71+
72 config := &Config{
73 Outdir: out,
74 RepoPath: repoPath,
75@@ -753,9 +768,11 @@ func main() {
76 Refs: refs,
77 Revs: revs,
78 Theme: theme,
79+ Logger: logger,
80 }
81+ config.Logger.Infof("%+v", config)
82
83 config.writeRepo()
84 url := filepath.Join("/", config.RepoName, "index.html")
85- fmt.Println(url)
86+ config.Logger.Info(url)
87 }