From effa1cfe5bf7a2bb092fc36c65573aa0dd805e0a Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 10 Nov 2023 01:00:45 -0700 Subject: [PATCH] Rename package to slogdedup --- README.md | 39 ++++++++++++++++++++++++++++++--------- append_handler.go | 2 +- append_handler_test.go | 2 +- doc.go | 12 ++++++------ helpers.go | 2 +- helpers_test.go | 2 +- ignore_handler.go | 2 +- ignore_handler_test.go | 2 +- increment_handler.go | 2 +- increment_handler_test.go | 2 +- overwrite_handler.go | 2 +- overwrite_handler_test.go | 2 +- 12 files changed, 46 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index acf738c..9d71320 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,16 @@ With this in mind, this repo was created with several different ways of deduplic ## Install `go get github.com/veqryn/slog-dedup` +```go +import ( + slogdedup "github.com/veqryn/slog-dedup" +) +``` + ## Usage ### Overwrite Older Duplicates Handler ```go -logger := slog.New(dedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) +logger := slog.New(slogdedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) logger.Info("this is the dedup overwrite handler", slog.String("duplicated", "zero"), slog.String("duplicated", "one"), @@ -62,7 +68,7 @@ Outputs: ### Ignore Newer Duplicates Handler ```go -logger := slog.New(dedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) +logger := slog.New(slogdedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) logger.Info("this is the dedup ignore handler", slog.String("duplicated", "zero"), slog.String("duplicated", "one"), @@ -81,7 +87,7 @@ Outputs: ### Increment Newer Duplicate Key Names Handler ```go -logger := slog.New(dedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) +logger := slog.New(slogdedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) logger.Info("this is the dedup incrementer handler", slog.String("duplicated", "zero"), slog.String("duplicated", "one"), @@ -102,7 +108,7 @@ Outputs: ### Append Duplicates Together in an Array Handler ```go -logger := slog.New(dedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) +logger := slog.New(slogdedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil)) logger.Info("this is the dedup appender handler", slog.String("duplicated", "zero"), slog.String("duplicated", "one"), @@ -131,12 +137,12 @@ import ( "log/slog" "os" - dedup "github.com/veqryn/slog-dedup" + slogdedup "github.com/veqryn/slog-dedup" ) func main() { // OverwriteHandler - overwriter := dedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + overwriter := slogdedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(overwriter)) /* @@ -154,7 +160,7 @@ func main() { ) // IgnoreHandler - ignorer := dedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + ignorer := slogdedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(ignorer)) /* @@ -172,7 +178,7 @@ func main() { ) // IncrementHandler - incrementer := dedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + incrementer := slogdedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(incrementer)) /* @@ -192,7 +198,7 @@ func main() { ) // AppendHandler - appender := dedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + appender := slogdedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(appender)) /* @@ -215,6 +221,21 @@ func main() { } ``` +## Breaking Changes +### O.1.0 -> 0.2.0 +Package renamed from `dedup` to `slogdedup`. +To fix, change this: +```go +import "github.com/veqryn/slog-dedup" +var overwriter = dedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) +``` +To this: +```go +import "github.com/veqryn/slog-dedup" +var overwriter = slogdedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) +``` +Named imports are unaffected. + ## Other Details ### Overwrite Handler Using an overwrite handler allows a slightly different style of logging that is less verbose. As an application moves deeper into domain functions, it is common that additional details or knowledge is uncovered. By overwriting keys with better and more explanatory values as you go, the final log lines are often easier to read and more informative. diff --git a/append_handler.go b/append_handler.go index b101e46..8615256 100644 --- a/append_handler.go +++ b/append_handler.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "context" diff --git a/append_handler_test.go b/append_handler_test.go index 26c37ba..ebf868b 100644 --- a/append_handler_test.go +++ b/append_handler_test.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "log/slog" diff --git a/doc.go b/doc.go index bee4523..1345ae1 100644 --- a/doc.go +++ b/doc.go @@ -1,5 +1,5 @@ /* -Package dedup provides structured logging (slog) deduplication for use with json logging +Package slogdedup provides structured logging (slog) deduplication for use with json logging (or any other format where duplicates are not appreciated). The main impetus behind this package is because most JSON tools do not like duplicate keys for their member properties/fields. Some of them will give errors or fail to parse the log line, and some may even crash. @@ -8,7 +8,7 @@ Unfortunately the default behavior of the stdlib slog handlers is to allow dupli Usage: // OverwriteHandler - overwriter := dedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + overwriter := slogdedup.NewOverwriteHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(overwriter)) // { @@ -24,7 +24,7 @@ Usage: ) // IgnoreHandler - ignorer := dedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + ignorer := slogdedup.NewIgnoreHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(ignorer)) // { @@ -40,7 +40,7 @@ Usage: ) // IncrementHandler - incrementer := dedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + incrementer := slogdedup.NewIncrementHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(incrementer)) // { @@ -58,7 +58,7 @@ Usage: ) // AppendHandler - appender := dedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil) + appender := slogdedup.NewAppendHandler(slog.NewJSONHandler(os.Stdout, nil), nil) slog.SetDefault(slog.New(appender)) // { @@ -77,4 +77,4 @@ Usage: slog.String("duplicated", "two"), ) */ -package dedup +package slogdedup diff --git a/helpers.go b/helpers.go index d8c8132..132b088 100644 --- a/helpers.go +++ b/helpers.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "fmt" diff --git a/helpers_test.go b/helpers_test.go index e5c5f3b..d8b3ffc 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "bytes" diff --git a/ignore_handler.go b/ignore_handler.go index 5161151..3eaa3c0 100644 --- a/ignore_handler.go +++ b/ignore_handler.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "context" diff --git a/ignore_handler_test.go b/ignore_handler_test.go index fc6c0d6..cfaac4d 100644 --- a/ignore_handler_test.go +++ b/ignore_handler_test.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "strings" diff --git a/increment_handler.go b/increment_handler.go index 17fdbca..7c2d42a 100644 --- a/increment_handler.go +++ b/increment_handler.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "context" diff --git a/increment_handler_test.go b/increment_handler_test.go index 1c29d9f..df215c1 100644 --- a/increment_handler_test.go +++ b/increment_handler_test.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "strings" diff --git a/overwrite_handler.go b/overwrite_handler.go index e660834..61a602c 100644 --- a/overwrite_handler.go +++ b/overwrite_handler.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "context" diff --git a/overwrite_handler_test.go b/overwrite_handler_test.go index e3494af..2974990 100644 --- a/overwrite_handler_test.go +++ b/overwrite_handler_test.go @@ -1,4 +1,4 @@ -package dedup +package slogdedup import ( "log/slog"