Commit 95810a1
Eric Bower
·
2023-08-09 09:29:22 -0400 EDT
parent 4cb9cc5
added logger
M
go.mod
+2,
-1
| ... | ... | @@ -7,11 +7,12 @@ require ( | |
| 7 | 7 | github.com/dustin/go-humanize v1.0.0 | |
| 8 | 8 | github.com/gogs/git-module v1.6.0 | |
| 9 | 9 | github.com/mergestat/timediff v0.0.3 | |
| 10 | + | go.uber.org/zap v1.25.0 | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| 12 | 13 | require ( | |
| 13 | 14 | github.com/dlclark/regexp2 v1.7.0 // indirect | |
| 14 | 15 | github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 // indirect | |
| 15 | - | github.com/stretchr/testify v1.8.0 // indirect | |
| 16 | + | go.uber.org/multierr v1.10.0 // indirect | |
| 16 | 17 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect | |
| 17 | 18 | ) |
M
go.sum
+7,
-5
| ... | ... | @@ -1,5 +1,6 @@ | |
| 1 | 1 | github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= | |
| 2 | 2 | github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= | |
| 3 | + | github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= | |
| 3 | 4 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | |
| 4 | 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | |
| 5 | 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| ... | ... | @@ -17,12 +18,14 @@ github.com/mergestat/timediff v0.0.3/go.mod h1:yvMUaRu2oetc+9IbPLYBJviz6sA7xz8OX | |
| 17 | 18 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | |
| 18 | 19 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | |
| 19 | 20 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | |
| 20 | - | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | |
| 21 | 21 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | |
| 22 | 22 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | |
| 23 | - | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | |
| 24 | - | github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= | |
| 25 | - | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | |
| 23 | + | github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | |
| 24 | + | go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= | |
| 25 | + | go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= | |
| 26 | + | go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= | |
| 27 | + | go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c= | |
| 28 | + | go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= | |
| 26 | 29 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
| 27 | 30 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= | |
| 28 | 31 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
| ... | ... | @@ -30,4 +33,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 | |
| 30 | 33 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |
| 31 | 34 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | |
| 32 | 35 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | |
| 33 | - | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
M
main.go
+23,
-6
| ... | ... | @@ -21,6 +21,7 @@ import ( | |
| 21 | 21 | "github.com/dustin/go-humanize" | |
| 22 | 22 | git "github.com/gogs/git-module" | |
| 23 | 23 | "github.com/mergestat/timediff" | |
| 24 | + | "go.uber.org/zap" | |
| 24 | 25 | ) | |
| 25 | 26 | ||
| 26 | 27 | //go:embed html/*.tmpl |
| ... | ... | @@ -48,8 +49,6 @@ type Config struct { | |
| 48 | 49 | // We offer a way to disable showing the latest commit in the output | |
| 49 | 50 | // for those who want a faster build time | |
| 50 | 51 | HideTreeLastCommit bool | |
| 51 | - | // chroma style | |
| 52 | - | Theme *chroma.Style | |
| 53 | 52 | ||
| 54 | 53 | // user-defined urls | |
| 55 | 54 | HomeUrl template.URL |
| ... | ... | @@ -60,6 +59,10 @@ type Config struct { | |
| 60 | 59 | Cache map[string]bool | |
| 61 | 60 | // pretty name for the repo | |
| 62 | 61 | RepoName string | |
| 62 | + | // logger | |
| 63 | + | Logger *zap.SugaredLogger | |
| 64 | + | // chroma style | |
| 65 | + | Theme *chroma.Style | |
| 63 | 66 | } | |
| 64 | 67 | ||
| 65 | 68 | // revision data |
| ... | ... | @@ -307,7 +310,7 @@ func (c *Config) writeHtml(writeData *WriteData) { | |
| 307 | 310 | bail(err) | |
| 308 | 311 | ||
| 309 | 312 | fp := filepath.Join(dir, writeData.Filename) | |
| 310 | - | fmt.Printf("writing (%s)\n", fp) | |
| 313 | + | c.Logger.Infof("writing (%s)", fp) | |
| 311 | 314 | ||
| 312 | 315 | w, err := os.OpenFile(fp, os.O_WRONLY|os.O_CREATE, 0755) | |
| 313 | 316 | bail(err) |
| ... | ... | @@ -682,7 +685,7 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 682 | 685 | var lastCommits []*git.Commit | |
| 683 | 686 | // `git rev-list` is pretty expensive here, so we have a flag to disable | |
| 684 | 687 | if pageData.Repo.HideTreeLastCommit { | |
| 685 | - | fmt.Println("skipping finding last commit for each file") | |
| 688 | + | c.Logger.Info("skipping finding last commit for each file") | |
| 686 | 689 | } else { | |
| 687 | 690 | lastCommits, err = repo.RevList([]string{pageData.RevData.ID}, git.RevListOptions{ | |
| 688 | 691 | Path: entry.Path, |
| ... | ... | @@ -708,7 +711,11 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 708 | 711 | )) | |
| 709 | 712 | } | |
| 710 | 713 | ||
| 711 | - | fmt.Printf("compilation complete (%s) branch (%s)\n", c.RepoName, pageData.RevData.RevName) | |
| 714 | + | c.Logger.Infof( | |
| 715 | + | "compilation complete (%s) branch (%s)", | |
| 716 | + | c.RepoName, | |
| 717 | + | pageData.RevData.RevName, | |
| 718 | + | ) | |
| 712 | 719 | ||
| 713 | 720 | c.writeLog(pageData, logs) | |
| 714 | 721 | c.writeLogDiffs(repo, pageData, logs) |
| ... | ... | @@ -745,6 +752,14 @@ func main() { | |
| 745 | 752 | ||
| 746 | 753 | theme := styles.Get(*themeFlag) | |
| 747 | 754 | ||
| 755 | + | lg, err := zap.NewProduction() | |
| 756 | + | if err != nil { | |
| 757 | + | bail(err) | |
| 758 | + | } | |
| 759 | + | ||
| 760 | + | logger := lg.Sugar() | |
| 761 | + | ||
| 762 | + | ||
| 748 | 763 | config := &Config{ | |
| 749 | 764 | Outdir: out, | |
| 750 | 765 | RepoPath: repoPath, |
| ... | ... | @@ -753,9 +768,11 @@ func main() { | |
| 753 | 768 | Refs: refs, | |
| 754 | 769 | Revs: revs, | |
| 755 | 770 | Theme: theme, | |
| 771 | + | Logger: logger, | |
| 756 | 772 | } | |
| 773 | + | config.Logger.Infof("%+v", config) | |
| 757 | 774 | ||
| 758 | 775 | config.writeRepo() | |
| 759 | 776 | url := filepath.Join("/", config.RepoName, "index.html") | |
| 760 | - | fmt.Println(url) | |
| 777 | + | config.Logger.Info(url) | |
| 761 | 778 | } |