mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 06:07:22 +01:00
Switch to a proper logging library
Structured logs can be enabled with `-log.json`.
This commit is contained in:
parent
03fce79e57
commit
40bae8dc31
9 changed files with 75 additions and 64 deletions
|
|
@ -12,11 +12,11 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/emersion/go-vcard"
|
||||
"github.com/emersion/go-webdav"
|
||||
"github.com/emersion/go-webdav/carddav"
|
||||
|
||||
"git.sr.ht/~sircmpwn/tokidoki/debug"
|
||||
)
|
||||
|
||||
func (b *filesystemBackend) AddressbookHomeSetPath(ctx context.Context) (string, error) {
|
||||
|
|
@ -95,14 +95,14 @@ func createDefaultAddressBook(path, localPath string) error {
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) AddressBook(ctx context.Context) (*carddav.AddressBook, error) {
|
||||
debug.Printf("filesystem.AddressBook()")
|
||||
log.Debug().Msg("filesystem.AddressBook()")
|
||||
localPath, err := b.localCardDAVPath(ctx, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localPath = filepath.Join(localPath, "addressbook.json")
|
||||
|
||||
debug.Printf("loading addressbook from %s", localPath)
|
||||
log.Debug().Str("local_path", localPath).Msg("loading addressbook")
|
||||
|
||||
data, readErr := ioutil.ReadFile(localPath)
|
||||
if os.IsNotExist(readErr) {
|
||||
|
|
@ -111,7 +111,7 @@ func (b *filesystemBackend) AddressBook(ctx context.Context) (*carddav.AddressBo
|
|||
return nil, err
|
||||
}
|
||||
urlPath = path.Join(urlPath, defaultResourceName) + "/"
|
||||
debug.Printf("creating default addressbook (URL:path): %s:%s", urlPath, localPath)
|
||||
log.Debug().Str("local_path", localPath).Str("url_path", urlPath).Msg("creating addressbook")
|
||||
err = createDefaultAddressBook(urlPath, localPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -131,7 +131,7 @@ func (b *filesystemBackend) AddressBook(ctx context.Context) (*carddav.AddressBo
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) GetAddressObject(ctx context.Context, objPath string, req *carddav.AddressDataRequest) (*carddav.AddressObject, error) {
|
||||
debug.Printf("filesystem.GetAddressObject(%s, %v)", objPath, req)
|
||||
log.Debug().Str("url_path", objPath).Msg("filesystem.GetAddressObject()")
|
||||
localPath, err := b.localCardDAVPath(ctx, objPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -213,12 +213,12 @@ func (b *filesystemBackend) loadAllContacts(ctx context.Context, propFilter []st
|
|||
return nil
|
||||
})
|
||||
|
||||
debug.Printf("filesystem.loadAllContacts() returning %d results from %s", len(result), localPath)
|
||||
log.Debug().Int("results", len(result)).Str("path", localPath).Msg("filesystem.loadAllContacts() successful")
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (b *filesystemBackend) ListAddressObjects(ctx context.Context, req *carddav.AddressDataRequest) ([]carddav.AddressObject, error) {
|
||||
debug.Printf("filesystem.ListAddressObjects(%v)", req)
|
||||
log.Debug().Msg("filesystem.ListAddressObjects()")
|
||||
var propFilter []string
|
||||
if req != nil && !req.AllProp {
|
||||
propFilter = req.Props
|
||||
|
|
@ -228,7 +228,7 @@ func (b *filesystemBackend) ListAddressObjects(ctx context.Context, req *carddav
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) QueryAddressObjects(ctx context.Context, query *carddav.AddressBookQuery) ([]carddav.AddressObject, error) {
|
||||
debug.Printf("filesystem.QueryAddressObjects(%v)", query)
|
||||
log.Debug().Msg("filesystem.QueryAddressObjects()")
|
||||
var propFilter []string
|
||||
if query != nil && !query.DataRequest.AllProp {
|
||||
propFilter = query.DataRequest.Props
|
||||
|
|
@ -243,7 +243,7 @@ func (b *filesystemBackend) QueryAddressObjects(ctx context.Context, query *card
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string, card vcard.Card, opts *carddav.PutAddressObjectOptions) (loc string, err error) {
|
||||
debug.Printf("filesystem.PutAddressObject(%v, %v, %v)", objPath, card, opts)
|
||||
log.Debug().Str("url_path", objPath).Msg("filesystem.PutAddressObject()")
|
||||
|
||||
// Object always get saved as <UID>.vcf
|
||||
dirname, _ := path.Split(objPath)
|
||||
|
|
@ -296,7 +296,7 @@ func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) DeleteAddressObject(ctx context.Context, path string) error {
|
||||
debug.Printf("filesystem.DeleteAddressObject(%s)", path)
|
||||
log.Debug().Str("url_path", path).Msg("filesystem.DeleteAddressObject()")
|
||||
|
||||
localPath, err := b.localCardDAVPath(ctx, path)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue