Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log messages #646

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,16 @@ func (b *Bucket) openBucket(value []byte) *Bucket {
// CreateBucket creates a new bucket at the given key and returns the new bucket.
// Returns an error if the key already exists, if the bucket name is blank, or if the bucket name is too long.
// The bucket instance is only valid for the lifetime of the transaction.
func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
func (b *Bucket) CreateBucket(key []byte) (rb *Bucket, err error) {
lg := b.tx.db.Logger()
lg.Debugf("Creating bucket %q", string(key))
defer func() {
if err != nil {
lg.Errorf("Creating bucket %q failed: %v", string(key), err)
} else {
lg.Debugf("Creating bucket %q successfully", string(key))
}
}()
if b.tx.db == nil {
return nil, errors.ErrTxClosed
} else if !b.tx.writable {
Expand Down Expand Up @@ -192,7 +201,17 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
// CreateBucketIfNotExists creates a new bucket if it doesn't already exist and returns a reference to it.
// Returns an error if the bucket name is blank, or if the bucket name is too long.
// The bucket instance is only valid for the lifetime of the transaction.
func (b *Bucket) CreateBucketIfNotExists(key []byte) (*Bucket, error) {
func (b *Bucket) CreateBucketIfNotExists(key []byte) (rb *Bucket, err error) {
lg := b.tx.db.Logger()
lg.Debugf("Creating bucket if not exist %q", string(key))
defer func() {
if err != nil {
lg.Errorf("Creating bucket if not exist %q failed: %v", string(key), err)
} else {
lg.Debugf("Creating bucket if not exist %q successfully", string(key))
}
}()

if b.tx.db == nil {
return nil, errors.ErrTxClosed
} else if !b.tx.writable {
Expand Down Expand Up @@ -249,7 +268,17 @@ func (b *Bucket) CreateBucketIfNotExists(key []byte) (*Bucket, error) {

// DeleteBucket deletes a bucket at the given key.
// Returns an error if the bucket does not exist, or if the key represents a non-bucket value.
func (b *Bucket) DeleteBucket(key []byte) error {
func (b *Bucket) DeleteBucket(key []byte) (err error) {
lg := b.tx.db.Logger()
lg.Debugf("Deleting bucket %q", string(key))
defer func() {
if err != nil {
lg.Errorf("Deleting bucket %q failed: %v", string(key), err)
} else {
lg.Debugf("Deleting bucket %q successfully", string(key))
}
}()

if b.tx.db == nil {
return errors.ErrTxClosed
} else if !b.Writable() {
Expand All @@ -269,7 +298,7 @@ func (b *Bucket) DeleteBucket(key []byte) error {

// Recursively delete all child buckets.
child := b.Bucket(key)
err := child.ForEachBucket(func(k []byte) error {
err = child.ForEachBucket(func(k []byte) error {
if err := child.DeleteBucket(k); err != nil {
return fmt.Errorf("delete bucket: %s", err)
}
Expand Down Expand Up @@ -316,7 +345,16 @@ func (b *Bucket) Get(key []byte) []byte {
// If the key exist then its previous value will be overwritten.
// Supplied value must remain valid for the life of the transaction.
// Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.
func (b *Bucket) Put(key []byte, value []byte) error {
func (b *Bucket) Put(key []byte, value []byte) (err error) {
lg := b.tx.db.Logger()
lg.Debugf("Putting key %q", string(key))
defer func() {
if err != nil {
lg.Errorf("Putting key %q failed: %v", string(key), err)
} else {
lg.Debugf("Putting key %q successfully", string(key))
}
}()
if b.tx.db == nil {
return errors.ErrTxClosed
} else if !b.Writable() {
Expand Down Expand Up @@ -353,7 +391,17 @@ func (b *Bucket) Put(key []byte, value []byte) error {
// Delete removes a key from the bucket.
// If the key does not exist then nothing is done and a nil error is returned.
// Returns an error if the bucket was created from a read-only transaction.
func (b *Bucket) Delete(key []byte) error {
func (b *Bucket) Delete(key []byte) (err error) {
lg := b.tx.db.Logger()
lg.Debugf("Deleting key %q", string(key))
defer func() {
if err != nil {
lg.Errorf("Deleting key %q failed: %v", string(key), err)
} else {
lg.Debugf("Deleting key %q successfully", string(key))
}
}()

if b.tx.db == nil {
return errors.ErrTxClosed
} else if !b.Writable() {
Expand Down
Loading
Loading