From 37dcdb91682060f572a300e7dfc49e8bf4a1b263 Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Tue, 4 Jul 2023 08:43:46 -0400 Subject: [PATCH] Logging is tuneable for better debugging experience --- cmd/demo/main.go | 4 +++- lexer.go | 6 +++--- lexer_test.go | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/demo/main.go b/cmd/demo/main.go index 7a7e74d..693372d 100644 --- a/cmd/demo/main.go +++ b/cmd/demo/main.go @@ -3,11 +3,13 @@ package main import ( "log" + "go.uber.org/zap/zapcore" + "code.ndumas.com/ndumas/wikilink-parser" ) 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 { item := item log.Printf("%#+v\n", item) diff --git a/lexer.go b/lexer.go index 53c1244..c7af191 100644 --- a/lexer.go +++ b/lexer.go @@ -38,12 +38,12 @@ const ( BlockRef = "#^" ) -func Lex(name, input string) *Lexer { +func Lex(name, input string, level zapcore.Level) *Lexer { encoderCfg := zap.NewProductionEncoderConfig() encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder config := zap.Config{ - Level: zap.NewAtomicLevelAt(zap.InfoLevel), + Level: zap.NewAtomicLevelAt(level), EncoderConfig: encoderCfg, OutputPaths: []string{ "./lexer.log", @@ -150,7 +150,7 @@ func (l *Lexer) emit(t LexemeType) { L := l.L.Named("emit").With( zap.String("item", i.String()), ) - L.Debug("emitting lexeme") + L.Info("emitting lexeme") l.Items = append(l.Items, i) l.SetStart(l.GetPos()) /* original concurrent implementation diff --git a/lexer_test.go b/lexer_test.go index e6c8f35..5b9b2a2 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -3,6 +3,8 @@ package wikilink_test import ( "testing" + "go.uber.org/zap/zapcore" + "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) { // t.Parallel() - l := wikilink.Lex("testLexer", tc.in) + l := wikilink.Lex("testLexer", tc.in, zapcore.WarnLevel) defer l.L.Sync() if len(tc.expected) != len(l.Items) { t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items))