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
2024-06-10 09:03:58 +00:00
parent 293c56fdaa
commit 257e46d2c8
8 changed files with 80 additions and 3 deletions
+11
View File
@@ -7,24 +7,35 @@ import (
"excalidraw-complete/stores/memory"
"excalidraw-complete/stores/sqlite"
"os"
"github.com/sirupsen/logrus"
)
func GetStore() core.DocumentStore {
storageType := os.Getenv("STORAGE_TYPE")
var store core.DocumentStore
storageField := logrus.Fields{
"storageType": storageType,
}
switch storageType {
case "filesystem":
basePath := os.Getenv("LOCAL_STORAGE_PATH")
storageField["basePath"] = basePath
store = filesystem.NewDocumentStore(basePath)
case "sqlite":
dataSourceName := os.Getenv("DATA_SOURCE_NAME")
storageField["dataSourceName"] = dataSourceName
store = sqlite.NewDocumentStore(dataSourceName)
case "s3":
bucketName := os.Getenv("S3_BUCKET_NAME")
storageField["bucketName"] = bucketName
store = aws.NewDocumentStore(bucketName)
default:
store = memory.NewDocumentStore()
storageField["storageType"] = "in-memory"
}
logrus.WithFields(storageField).Info("Use storage")
return store
}