Skip to content

Commit

Permalink
Use the new logging interface throughout (#17)
Browse files Browse the repository at this point in the history
No more explicit references to log15! #minor
  • Loading branch information
lhchavez authored Dec 4, 2021
1 parent f7e4fcf commit e1aa073
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 202 deletions.
18 changes: 14 additions & 4 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"time"

base "github.com/omegaup/go-base/v2"
tracing "github.com/omegaup/go-base/v2/tracing"
base "github.com/omegaup/go-base/v3"
tracing "github.com/omegaup/go-base/v3/tracing"

git "github.com/libgit2/git2go/v33"
"github.com/pkg/errors"
Expand Down Expand Up @@ -751,9 +751,19 @@ func handleBrowse(

lockfile := NewLockfile(repository.Path())
if ok, err := lockfile.TryRLock(); !ok {
protocol.log.Info("Waiting for the lockfile", "err", err)
protocol.log.Info(
"Waiting for the lockfile",
map[string]interface{}{
"err": err,
},
)
if err := lockfile.RLock(); err != nil {
protocol.log.Crit("Failed to acquire the lockfile", "err", err)
protocol.log.Error(
"Failed to acquire the lockfile",
map[string]interface{}{
"err": err,
},
)
return err
}
}
Expand Down
23 changes: 12 additions & 11 deletions browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"reflect"
"testing"

base "github.com/omegaup/go-base/v2"
log15 "github.com/omegaup/go-base/logging/log15"
base "github.com/omegaup/go-base/v3"

git "github.com/libgit2/git2go/v33"
)

func TestHandleRefs(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestHandleRefs(t *testing.T) {
}

func TestHandleRefsWithReferenceDiscoveryCallback(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
ReferenceDiscoveryCallback: func(
ctx context.Context,
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestHandleRefsWithReferenceDiscoveryCallback(t *testing.T) {
}

func TestHandleRestrictedRefs(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestHandleRestrictedRefs(t *testing.T) {
}

func TestHandleArchiveCommit(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestHandleArchiveCommit(t *testing.T) {
}

func TestHandleLog(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -229,7 +230,7 @@ func TestHandleLog(t *testing.T) {
}

func TestHandleLogCommit(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -278,7 +279,7 @@ func TestHandleLogCommit(t *testing.T) {
}

func TestHandleShowCommit(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -324,7 +325,7 @@ func TestHandleShowCommit(t *testing.T) {
}

func TestHandleShowTree(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestHandleShowTree(t *testing.T) {
}

func TestHandleShowBlob(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
Log: log,
})
Expand Down Expand Up @@ -416,7 +417,7 @@ func TestHandleShowBlob(t *testing.T) {
}

func TestHandleNotFound(t *testing.T) {
log := base.StderrLog(false)
log, _ := log15.New("info", false)
protocol := NewGitProtocol(GitProtocolOpts{
ReferenceDiscoveryCallback: func(
ctx context.Context,
Expand Down
54 changes: 43 additions & 11 deletions commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"sort"
"strings"

"github.com/omegaup/go-base/v2/tracing"
"github.com/omegaup/go-base/v3/logging"
"github.com/omegaup/go-base/v3/tracing"

"github.com/inconshreveable/log15"
git "github.com/libgit2/git2go/v33"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -198,7 +198,7 @@ func SplitTree(
originalRepository *git.Repository,
paths []string,
repository *git.Repository,
log log15.Logger,
log logging.Logger,
) (*git.Tree, error) {
treebuilder, err := repository.TreeBuilder()
if err != nil {
Expand Down Expand Up @@ -262,7 +262,14 @@ func SplitTree(
}
defer tree.Free()

log.Debug("Creating subtree", "name", name, "contents", subpaths, "id", tree.Id().String())
log.Debug(
"Creating subtree",
map[string]interface{}{
"name": name,
"contents": subpaths,
"id": tree.Id().String(),
},
)
if err = treebuilder.Insert(name, tree.Id(), originalEntry.Filemode); err != nil {
return errors.Wrapf(err, "failed to insert %s into treebuilder", name)
}
Expand Down Expand Up @@ -315,7 +322,7 @@ func SplitCommit(
repository *git.Repository,
author, committer *git.Signature,
commitMessageTag string,
log log15.Logger,
log logging.Logger,
) ([]SplitCommitResult, error) {
originalTree, err := originalCommit.Tree()
if err != nil {
Expand All @@ -335,10 +342,23 @@ func SplitCommit(
return ErrObjectLimitExceeded
}
path := path.Join(parent, entry.Name)
log.Debug("Considering", "path", path, "entry", *entry)
log.Debug(
"Considering",
map[string]interface{}{
"path": path,
"entry": *entry,
},
)
for i, description := range descriptions {
if description.ContainsPath(path) {
log.Debug("Found a match for a path", "path", path, "entry", *entry, "description", description)
log.Debug(
"Found a match for a path",
map[string]interface{}{
"path": path,
"entry": *entry,
"description": description,
},
)
treePaths[i] = append(treePaths[i], path)
break
}
Expand Down Expand Up @@ -444,7 +464,7 @@ func SpliceCommit(
reference *git.Reference,
commitMessageTag string,
newPackPath string,
log log15.Logger,
log logging.Logger,
) ([]*GitCommand, error) {
newRepository, err := openRepository(context.TODO(), repository.Path())
if err != nil {
Expand Down Expand Up @@ -682,7 +702,7 @@ func SpliceCommit(
func BuildTree(
repository *git.Repository,
files map[string]io.Reader,
log log15.Logger,
log logging.Logger,
) (*git.Tree, error) {
treebuilder, err := repository.TreeBuilder()
if err != nil {
Expand All @@ -703,7 +723,14 @@ func BuildTree(
if err != nil {
return nil, errors.Wrapf(err, "failed to create blob for %s", name)
}
log.Debug("Creating blob", "path", name, "len", len(contents), "id", oid)
log.Debug(
"Creating blob",
map[string]interface{}{
"path": name,
"len": len(contents),
"id": oid,
},
)
if err = treebuilder.Insert(name, oid, 0100644); err != nil {
return nil, errors.Wrapf(err, "failed to insert %s into treebuilder", name)
}
Expand Down Expand Up @@ -741,7 +768,12 @@ func BuildTree(
if err != nil {
return nil, errors.Wrap(err, "failed to create tree")
}
log.Debug("Creating tree", "id", mergedTreeID)
log.Debug(
"Creating tree",
map[string]interface{}{
"id": mergedTreeID,
},
)
return repository.LookupTree(mergedTreeID)
}

Expand Down
23 changes: 17 additions & 6 deletions commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

base "github.com/omegaup/go-base/v2"
"github.com/omegaup/go-base/logging/log15"

git "github.com/libgit2/git2go/v33"
)
Expand All @@ -29,7 +29,7 @@ func TestSplitTrees(t *testing.T) {
}
defer repository.Free()

log := base.StderrLog(false)
log, _ := log15.New("info", false)

originalTree, err := BuildTree(
repository,
Expand Down Expand Up @@ -95,7 +95,13 @@ func TestSplitTrees(t *testing.T) {
newPaths := make([]string, 0)
err = splitTree.Walk(func(parent string, entry *git.TreeEntry) error {
path := path.Join(parent, entry.Name)
log.Debug("Considering", "path", path, "entry", *entry)
log.Debug(
"Considering",
map[string]interface{}{
"path": path,
"entry": *entry,
},
)
if entry.Type != git.ObjectBlob {
return nil
}
Expand Down Expand Up @@ -127,7 +133,7 @@ func TestMergeTrees(t *testing.T) {
}
defer repo.Free()

log := base.StderrLog(false)
log, _ := log15.New("info", false)

type testEntry struct {
trees []map[string]io.Reader
Expand Down Expand Up @@ -244,7 +250,7 @@ func TestSpliceCommit(t *testing.T) {
}
defer repository.Free()

log := base.StderrLog(false)
log, _ := log15.New("info", false)

originalTree, err := BuildTree(
repository,
Expand Down Expand Up @@ -338,5 +344,10 @@ func TestSpliceCommit(t *testing.T) {
t.Fatalf("Error splicing commit: %v", err)
}

log.Debug("Commands changed", "newCommands", newCommands)
log.Debug(
"Commands changed",
map[string]interface{}{
"newCommands": newCommands,
},
)
}
17 changes: 11 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ module github.com/omegaup/githttp/v2
go 1.17

require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
github.com/go-stack/stack v1.8.1 // indirect
github.com/libgit2/git2go/v33 v33.0.4
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/omegaup/go-base/v2 v2.3.0
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/omegaup/go-base/logging/log15 v0.0.0-20211204182432-a117421dbd30
github.com/omegaup/go-base/v3 v3.1.0
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
)

require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect
)
40 changes: 16 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac h1:n1DqxAo4oWPMvH1+v+DLYlMCecgumhhgnxAPdqDIFHI=
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o=
github.com/libgit2/git2go/v33 v33.0.4 h1:37xovFBzibhDEdQRLbfWwx3a44JhOIY06UICn2teenc=
github.com/libgit2/git2go/v33 v33.0.4/go.mod h1:KdpqkU+6+++4oHna/MIOgx4GCQ92IPCdpVRMRI80J+4=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/omegaup/go-base/v2 v2.0.0 h1:A4TGNKDbbAiF55EfxPh5r8knS/zDpFFJpFCYerqByzE=
github.com/omegaup/go-base/v2 v2.0.0/go.mod h1:k5PYTZcULZt7Dbx67WI0Wk3WHJSMmyadEG1aWx6YbVg=
github.com/omegaup/go-base/v2 v2.1.0 h1:pehTzNMArOQrVBOa2oLhZDIhWSU80phIHrBi+gL46LY=
github.com/omegaup/go-base/v2 v2.1.0/go.mod h1:DotC1e60GE6S+iqe9RyusanekwK/eyU/YL3so86X3SA=
github.com/omegaup/go-base/v2 v2.2.0 h1:bb4PrDOlJ+v17QHblBN3QGNTWoRhtgOW+k7x9q2L9Ik=
github.com/omegaup/go-base/v2 v2.2.0/go.mod h1:DotC1e60GE6S+iqe9RyusanekwK/eyU/YL3so86X3SA=
github.com/omegaup/go-base/v2 v2.3.0 h1:u5juOm0O96ZeuJu3xYSwvyGtstIkCEDT/F016gzSfow=
github.com/omegaup/go-base/v2 v2.3.0/go.mod h1:DotC1e60GE6S+iqe9RyusanekwK/eyU/YL3so86X3SA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/omegaup/go-base/logging/log15 v0.0.0-20211204182432-a117421dbd30 h1:NzSSVKqF1u8vDe4ooKP/fxWR8rr4QtzYJYADK+X/UUU=
github.com/omegaup/go-base/logging/log15 v0.0.0-20211204182432-a117421dbd30/go.mod h1:bZLSqNMf9PDRAYKax8zOS0a6si1t0BUMHkh3SRZ9dEU=
github.com/omegaup/go-base/v3 v3.0.0/go.mod h1:mJFH+bckd4aAXcpXDBFN6Et5p3sxYsHCxK8pUDp0YlM=
github.com/omegaup/go-base/v3 v3.1.0 h1:8WT7h5gTSF0pJpxuajxtpmU2Cq09VDIfziooiSKn7Go=
github.com/omegaup/go-base/v3 v3.1.0/go.mod h1:mJFH+bckd4aAXcpXDBFN6Et5p3sxYsHCxK8pUDp0YlM=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -30,14 +25,11 @@ golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAd
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191206220618-eeba5f6aabab/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Loading

0 comments on commit e1aa073

Please sign in to comment.