refactor: Use interface for logger instead of private struct

This commit is contained in:
Felicitas Pojtinger
2022-01-01 23:12:32 +01:00
parent 9058942443
commit cfbb936954
4 changed files with 21 additions and 10 deletions

View File

@@ -11,10 +11,10 @@ import (
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/ioext"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/cache"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory"
"github.com/pojntfx/stfs/pkg/logging"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/spf13/afero"
)
@@ -54,7 +54,7 @@ type File struct {
cleanWriteBuf func() error
onHeader func(hdr *models.Header)
log *logging.JSONLogger
log logging.StructuredLogger
}
func NewFile(
@@ -75,7 +75,7 @@ func NewFile(
info os.FileInfo,
onHeader func(hdr *models.Header),
log *logging.JSONLogger,
log logging.StructuredLogger,
) *File {
return &File{
readOps: readOps,

View File

@@ -6,7 +6,7 @@ import (
"os"
"time"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/logging"
)
type FileInfo struct {
@@ -18,7 +18,7 @@ type FileInfo struct {
modTime time.Time
isDir bool
log *logging.JSONLogger
log logging.StructuredLogger
}
func NewFileInfo(
@@ -28,7 +28,7 @@ func NewFileInfo(
modTime time.Time,
isDir bool,
log *logging.JSONLogger,
log logging.StructuredLogger,
) *FileInfo {
return &FileInfo{
name: name,
@@ -44,7 +44,7 @@ func NewFileInfo(
func NewFileInfoFromTarHeader(
hdr *tar.Header,
log *logging.JSONLogger,
log logging.StructuredLogger,
) *FileInfo {
return &FileInfo{
name: hdr.FileInfo().Name(),

View File

@@ -14,10 +14,10 @@ import (
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
ifs "github.com/pojntfx/stfs/internal/fs"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/cache"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory"
"github.com/pojntfx/stfs/pkg/logging"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/spf13/afero"
)
@@ -35,7 +35,7 @@ type STFS struct {
ioLock sync.Mutex
onHeader func(hdr *models.Header)
log *logging.JSONLogger
log logging.StructuredLogger
}
func NewSTFS(
@@ -49,7 +49,7 @@ func NewSTFS(
ignorePermissionFlags bool,
onHeader func(hdr *models.Header),
log *logging.JSONLogger,
log logging.StructuredLogger,
) *STFS {
return &STFS{
readOps: readOps,

11
pkg/logging/structured.go Normal file
View File

@@ -0,0 +1,11 @@
package logging
import (
golog "github.com/fclairamb/go-log"
)
type StructuredLogger interface {
golog.Logger
Trace(event string, keyvals ...interface{})
}