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

View File

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

View File

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