Logging is tuneable for better debugging experience

main
Nick Dumas 1 year ago
parent ee6cad7662
commit 37dcdb9168

@ -3,11 +3,13 @@ package main
import ( import (
"log" "log"
"go.uber.org/zap/zapcore"
"code.ndumas.com/ndumas/wikilink-parser" "code.ndumas.com/ndumas/wikilink-parser"
) )
func main() { func main() {
l := wikilink.Lex("debugLexer", `this is a [[wikilink]]`) l := wikilink.Lex("debugLexer", `this is a [[wikilink]]`, zapcore.InfoLevel)
for _, item := range l.Items { for _, item := range l.Items {
item := item item := item
log.Printf("%#+v\n", item) log.Printf("%#+v\n", item)

@ -38,12 +38,12 @@ const (
BlockRef = "#^" BlockRef = "#^"
) )
func Lex(name, input string) *Lexer { func Lex(name, input string, level zapcore.Level) *Lexer {
encoderCfg := zap.NewProductionEncoderConfig() encoderCfg := zap.NewProductionEncoderConfig()
encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
config := zap.Config{ config := zap.Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel), Level: zap.NewAtomicLevelAt(level),
EncoderConfig: encoderCfg, EncoderConfig: encoderCfg,
OutputPaths: []string{ OutputPaths: []string{
"./lexer.log", "./lexer.log",
@ -150,7 +150,7 @@ func (l *Lexer) emit(t LexemeType) {
L := l.L.Named("emit").With( L := l.L.Named("emit").With(
zap.String("item", i.String()), zap.String("item", i.String()),
) )
L.Debug("emitting lexeme") L.Info("emitting lexeme")
l.Items = append(l.Items, i) l.Items = append(l.Items, i)
l.SetStart(l.GetPos()) l.SetStart(l.GetPos())
/* original concurrent implementation /* original concurrent implementation

@ -3,6 +3,8 @@ package wikilink_test
import ( import (
"testing" "testing"
"go.uber.org/zap/zapcore"
"code.ndumas.com/ndumas/wikilink-parser" "code.ndumas.com/ndumas/wikilink-parser"
) )
@ -277,7 +279,7 @@ func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix
return tc, func(t *testing.T) { return tc, func(t *testing.T) {
// t.Parallel() // t.Parallel()
l := wikilink.Lex("testLexer", tc.in) l := wikilink.Lex("testLexer", tc.in, zapcore.WarnLevel)
defer l.L.Sync() defer l.L.Sync()
if len(tc.expected) != len(l.Items) { if len(tc.expected) != len(l.Items) {
t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items)) t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items))

Loading…
Cancel
Save