package log

import (
	"context"
	"testing"
	"time"
)

func TestNewLogger(t *testing.T) {
	w := NewFileWriter("log", "./test")
	lg := NewLogger(LevelDebug, "", 1, w)
	lg.Error("NewLogger: %s", time.Now())
	lg.Warn("NewLogger: %s", time.Now())
	lg.Info("NewLogger: %s", time.Now())
	lg.Debug("NewLogger: %s", time.Now())
}

// goos: windows
// goarch: amd64
// pkg: wcs/lib/log
// cpu: 12th Gen Intel(R) Core(TM) i5-12490F
// BenchmarkNewFileWriter
// BenchmarkNewFileWriter-12    	   69715	     17585 ns/op
func BenchmarkNewFileWriter(b *testing.B) {
	w := NewFileWriter("log", "./test")
	lg := NewLogger(LevelDebug, "", 1, w)
	for i := 0; i < b.N; i++ {
		lg.Error("NewLogger: %s", time.Now())
		lg.Warn("NewLogger: %s", time.Now())
		lg.Info("NewLogger: %s", time.Now())
		lg.Debug("NewLogger: %s", time.Now())
	}
}

func TestNewPrinter(t *testing.T) {
	console := ConsoleWith(LevelDebug, 2)
	console.Debug("NewPrinter: %s", time.Now())
	console.Debug("NewPrinter: %s", time.Now())
	console.Debug("NewPrinter: %s", time.Now())
	console.Debug("NewPrinter: %s", time.Now())
}

func TestNewAutoClear(t *testing.T) {
	ac := &AutoClear{
		LogPath: "./",
	}
	go ac.Start(context.Background())
}
