Add structured logging to documentStore methods

To troubleshoot reported issues, we add more debugging outputs in
the logging. This includes detailed, structured logs in the Create
and FindID methods to provide better traceability and debuggability.

These changes help diagnose issues by providing detailed context in
the logs, which should improve the ability to identify and resolve
problems.

See also: #9
This commit is contained in:
patwie committed 2024-06-10 09:11:26 +00:00
1 parent 293c56fdaa
commit 257e46d2c8
8 files changed
+80 -3

No files matched your search

+10
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/oklog/ulid/v2"
"github.com/sirupsen/logrus"
)
var savedDocuments = make(map[string]core.Document)
@@ -18,14 +19,23 @@ func NewDocumentStore() core.DocumentStore {
}
func (s *documentStore) FindID(ctx context.Context, id string) (*core.Document, error) {
log := logrus.WithField("document_id", id)
if val, ok := savedDocuments[id]; ok {
log.Info("Document retrieved successfully")
return &val, nil
}
log.WithField("error", "document not found").Warn("Document with specified ID not found")
return nil, fmt.Errorf("document with id %s not found", id)
}
func (s *documentStore) Create(ctx context.Context, document *core.Document) (string, error) {
id := ulid.Make().String()
savedDocuments[id] = *document
log := logrus.WithFields(logrus.Fields{
"document_id": id,
"data_length": len(document.Data.Bytes()),
})
log.Info("Document created successfully")
return id, nil
}