Add logging to storage package

This commit is contained in:
2024-12-16 22:38:21 +01:00
parent 03e78c3e6b
commit 032ae1354c
5 changed files with 177 additions and 10 deletions

View File

@@ -27,6 +27,9 @@ type Options struct {
// NewService creates a new Storage instance with the default options and the given rootDir root directory.
func NewService(rootDir string) *Service {
getLogger().Debug("creating new storage service",
"rootDir", rootDir,
"options", "default")
return NewServiceWithOptions(rootDir, Options{
Fs: &osFS{},
NewGitClient: git.New,
@@ -35,14 +38,23 @@ func NewService(rootDir string) *Service {
// NewServiceWithOptions creates a new Storage instance with the given options and the given rootDir root directory.
func NewServiceWithOptions(rootDir string, options Options) *Service {
log := getLogger()
log.Debug("creating new storage service with custom options",
"rootDir", rootDir)
if options.Fs == nil {
log.Debug("filesystem not provided, using default osFS")
options.Fs = &osFS{}
}
if options.NewGitClient == nil {
log.Debug("git client factory not provided, using default git.New")
options.NewGitClient = git.New
}
log.Info("storage service created",
"rootDir", rootDir)
return &Service{
fs: options.Fs,
newGitClient: options.NewGitClient,