Files
any2anexoj/internal/stdout.go
Natercio Moniz 70bd8622de
All checks were successful
Tests / tests (pull_request) Successful in 17s
isolate record reading and writing from processing
2025-11-13 14:07:08 +00:00

32 lines
514 B
Go

package internal
import (
"fmt"
"io"
"os"
"time"
)
type ReportLogger struct {
counter int
writer io.Writer
}
func NewStdOutLogger() *ReportLogger {
return &ReportLogger{
writer: os.Stdout,
}
}
func NewReportLogger(w io.Writer) *ReportLogger {
return &ReportLogger{
writer: w,
}
}
func (rl *ReportLogger) Write(ri ReportItem) error {
rl.counter++
_, err := fmt.Fprintf(rl.writer, "%6d - realised %+f on %s\n", rl.counter, ri.RealisedPnL(), ri.SellTimestamp.Format(time.RFC3339))
return err
}