A compatible log extension
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
log/logext_test.go

76 lines
1.0 KiB

package log
import (
"database/sql"
"fmt"
"testing"
_ "github.com/mattn/go-sqlite3"
)
func TestLog(t *testing.T) {
SetOutputLevel(Ldebug)
Debugf("Debug: foo\n")
Debug("Debug: foo")
Infof("Info: foo\n")
Info("Info: foo")
Warnf("Warn: foo\n")
Warn("Warn: foo")
Errorf("Error: foo\n")
Error("Error: foo")
SetOutputLevel(Linfo)
Debugf("Debug: foo\n")
Debug("Debug: foo")
Infof("Info: foo\n")
Info("Info: foo")
Warnf("Warn: foo\n")
Warn("Warn: foo")
Errorf("Error: foo\n")
Error("Error: foo")
db, err := sql.Open("sqlite3", "./log.db")
if err != nil {
t.Fatal(err)
}
w, err := NewDBWriter(db)
if err != nil {
fmt.Println(err)
t.Fatal(err)
}
SetOutput(w)
SetFlags(RmColorFlags(Flags()))
// output all
SetOutputLevel(Lall)
Debugf("Debug: foo\n")
Debug("Debug: foo")
Infof("Info: foo\n")
Info("Info: foo")
Warnf("Warn: foo\n")
Warn("Warn: foo")
Errorf("Error: foo\n")
Error("Error: foo")
// output none
SetOutputLevel(Lnone)
Warnf("Warn: foo\n")
Warn("Warn: foo")
Errorf("Error: foo\n")
Error("Error: foo")
}