Files
Excalidraw/stores/storage.go
T
patwie 257e46d2c8 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
2024-06-10 09:11:26 +00:00

42 lines
1.0 KiB
Go

package stores
import (
"excalidraw-complete/core"
"excalidraw-complete/stores/aws"
"excalidraw-complete/stores/filesystem"
"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
}