package logs

import (
	"os"
	"testing"
)

const (
	id = "192.168.111.123"
)

func TestNewManager(t *testing.T) {
	tmpDir := os.TempDir()
	t.Log(tmpDir)
	mgr := NewManager("carrier", tmpDir)
	lg, err := mgr.Get(id)
	if err != nil {
		t.Error(err)
		return
	}
	lg.Safety("This a log test case by %s", id)
	lg.Action("This a log test case by %s", id)
	lg.Device("This a log test case by %s", id)
	lg.Println("This a log test case by %s", id)

	slg := lg.Session()
	slg.Safety("This log with session test case by %s", id)
	slg.Action("This log with session test case by %s", id)
	slg.Device("This log with session test case by %s", id)
	slg.Println("This log with session test case by %s", id)

	_ = lg.Close()
}

func BenchmarkNewManager(b *testing.B) {
	tmpDir := os.TempDir()
	b.Log(tmpDir)
	mgr := NewManager("carrier", tmpDir)
	lg, err := mgr.Get(id)
	if err != nil {
		b.Error(err)
		return
	}
	defer func() {
		_ = lg.Close()
	}()
	for i := 0; i < b.N; i++ {
		lg.Println("%d", i)
	}
}
