Skip to content

Commit

Permalink
historyarchive: Make the library target the same log as Horizon (#5178)
Browse files Browse the repository at this point in the history
* Change logging provider to Horizon's default rather than logrus
  • Loading branch information
Shaptic authored Jan 23, 2024
1 parent a8b5c8e commit 0ddb36f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions historyarchive/archive_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"path"

lru "github.com/hashicorp/golang-lru"
log "github.com/sirupsen/logrus"
log "github.com/stellar/go/support/log"
)

type CacheOptions struct {
Cache bool

Path string
MaxFiles uint
Log *log.Entry
}

type ArchiveBucketCache struct {
Expand All @@ -25,8 +26,11 @@ type ArchiveBucketCache struct {
// MakeArchiveBucketCache creates a cache on the disk at the given path that
// acts as an LRU cache, mimicking a particular upstream.
func MakeArchiveBucketCache(opts CacheOptions) (*ArchiveBucketCache, error) {
log_ := log.
WithField("subservice", "fs-cache").
log_ := opts.Log
if opts.Log == nil {
log_ = log.WithField("subservice", "fs-cache")
}
log_ = log_.
WithField("path", opts.Path).
WithField("cap", opts.MaxFiles)

Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func NewSystem(config Config) (System, error) {
CacheConfig: historyarchive.CacheOptions{
Cache: true,
Path: path.Join(config.CaptiveCoreStoragePath, "bucket-cache"),
Log: log.WithField("subservice", "ha-cache"),
MaxFiles: 150,
},
},
Expand Down
3 changes: 1 addition & 2 deletions support/log/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"

gerr "github.com/go-errors/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -198,7 +197,7 @@ func (e *Entry) StartTest(level logrus.Level) func() []logrus.Entry {
e.entry.Logger.AddHook(hook)

old := e.entry.Logger.Out
e.entry.Logger.Out = ioutil.Discard
e.entry.Logger.Out = io.Discard

oldLevel := e.entry.Logger.GetLevel()
e.entry.Logger.SetLevel(level)
Expand Down

0 comments on commit 0ddb36f

Please sign in to comment.