Files
any2anexoj/internal/stdout.go
Natercio Moniz d913e5fb53
Some checks failed
Tests / tests (pull_request) Failing after 5s
handle context cancelation
2025-11-14 08:59:10 +00:00

33 lines
544 B
Go

package internal
import (
"context"
"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(_ context.Context, 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
}