summaryrefslogtreecommitdiff
path: root/datalogger/logger.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2022-11-16 10:20:06 -0500
committerWill Hawkins <[email protected]>2022-11-16 10:22:20 -0500
commit10a52af363b0d52d78af0158cbaa404a1ce35b82 (patch)
tree5625c03873c597e4dfdf3a267e6bc0eb53def666 /datalogger/logger.go
parent86f822c37f8fcc70d3a1085f4769ec58752f50c1 (diff)
[Feature] Add a Null Data Logger
The Null Data Logger will do nothing. This makes it possible to write unconditional code around logging -- there will *always* be a logger but sometimes that logger does, well, nothing.
Diffstat (limited to 'datalogger/logger.go')
-rw-r--r--datalogger/logger.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/datalogger/logger.go b/datalogger/logger.go
index a6789d2..4c3b080 100644
--- a/datalogger/logger.go
+++ b/datalogger/logger.go
@@ -38,6 +38,16 @@ type CSVDataLogger[T any] struct {
destination io.WriteCloser
}
+type NullDataLogger[T any] struct{}
+
+func CreateNullDataLogger[T any]() DataLogger[T] {
+ return &NullDataLogger[T]{}
+}
+
+func (_ *NullDataLogger[T]) LogRecord(_ T) {}
+func (_ *NullDataLogger[T]) Export() bool { return true }
+func (_ *NullDataLogger[T]) Close() bool { return true }
+
func CreateCSVDataLogger[T any](filename string) (DataLogger[T], error) {
data := make([]T, 0)
destination, err := os.Create(filename)