mirror of
https://github.com/kopia/kopia.git
synced 2026-03-15 04:38:56 -04:00
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package blob
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
type loggingStorage struct {
|
|
Storage
|
|
}
|
|
|
|
func (s *loggingStorage) BlockExists(id string) (bool, error) {
|
|
result, err := s.Storage.BlockExists(id)
|
|
log.Printf("BlockExists(%#v)=%#v,%#v", id, result, err)
|
|
return result, err
|
|
}
|
|
|
|
func (s *loggingStorage) GetBlock(id string) ([]byte, error) {
|
|
result, err := s.Storage.GetBlock(id)
|
|
if len(result) < 20 {
|
|
log.Printf("GetBlock(%#v)=(%#v, %#v)", id, result, err)
|
|
} else {
|
|
log.Printf("GetBlock(%#v)=({%#v bytes}, %#v)", id, len(result), err)
|
|
}
|
|
return result, err
|
|
}
|
|
|
|
func (s *loggingStorage) PutBlock(id string, data io.ReadCloser, options PutOptions) error {
|
|
err := s.Storage.PutBlock(id, data, options)
|
|
log.Printf("PutBlock(%#v, %#v)=%#v", id, options, err)
|
|
return err
|
|
}
|
|
|
|
func (s *loggingStorage) DeleteBlock(id string) error {
|
|
err := s.Storage.DeleteBlock(id)
|
|
log.Printf("DeleteBlock(%#v)=%#v", id, err)
|
|
return err
|
|
}
|
|
|
|
func (s *loggingStorage) ListBlocks(prefix string) chan (BlockMetadata) {
|
|
log.Printf("ListBlocks(%#v)", prefix)
|
|
return s.Storage.ListBlocks(prefix)
|
|
}
|
|
|
|
func (s *loggingStorage) Flush() error {
|
|
log.Printf("Flush()")
|
|
return s.Storage.Flush()
|
|
}
|
|
|
|
// NewLoggingWrapper returns a Storage wrapper that logs all storage commands.
|
|
func NewLoggingWrapper(wrapped Storage) Storage {
|
|
return &loggingStorage{wrapped}
|
|
}
|