From 1b4c76c3a14983e98454423ef828610e1df3a75d Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Sun, 7 Apr 2024 12:27:05 -0600 Subject: [PATCH] migrated to simplelog --- examples/collisions.go | 18 +++++++++++------- examples/main.go | 8 +++++--- examples/reallylong.go | 6 ++++-- tind_test.go | 11 ++++++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/examples/collisions.go b/examples/collisions.go index 54042ce..d1745f5 100644 --- a/examples/collisions.go +++ b/examples/collisions.go @@ -1,14 +1,14 @@ package main import ( - "log" "sync" + log "git.staur.ca/stobbsm/simplelog" "git.staur.ca/stobbsm/tind" ) var ( - RuneSet = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}/';:.>,<`~") + RuneSet = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}/';:.>,<`~") ) const runs uint64 = 10000 @@ -16,14 +16,14 @@ const runs uint64 = 10000 // CollisionChecks runs different tests to check for collisions, and get's the average func CollisionChecks() { wg := new(sync.WaitGroup) - log.Println("Using multiple configurations, test for collisions multiple times") - sizes := []int{4,5,6,7,8,9,10,11,12,13,14,15,16} + log.Info("examples.CollisionChecks").Msg("Using multiple configurations, test for collisions multiple times") + sizes := []int{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} end := len(RuneSet) - + for i := 4; i < end; i++ { for _, v := range sizes { v := v - rs :=RuneSet[:i] + rs := RuneSet[:i] wg.Add(1) go collisionCheck(v, rs, wg, len(rs)) } @@ -37,7 +37,11 @@ func collisionCheck(size int, runeset []rune, wg *sync.WaitGroup, runesize int) for i := uint64(0); i < runs; i++ { total += runCheck(tind.New().WithSize(size).WithRuneset(runeset)) } - log.Printf("runset size: %d, id size: %d, average iterations before collision: %d", runesize, size, total/runs) + log.Info("examples.collisionCheck"). + Uint64("average iterations", total/runs). + Int("runesize", runesize). + Int("size", size). + Send() } func runCheck(tconfig *tind.Config) uint64 { diff --git a/examples/main.go b/examples/main.go index 881640e..d3f32ff 100644 --- a/examples/main.go +++ b/examples/main.go @@ -1,11 +1,13 @@ package main -import "log" +import ( + log "git.staur.ca/stobbsm/simplelog" +) func main() { - log.Println("Example: GenWithDefaults") + log.Info("examples.main").Msg("Example: GenWithDefaults") GenWithDefaults() - log.Println("Example: CollisionChecks") + log.Info("examples.main").Msg("Example: CollisionChecks") CollisionChecks() } diff --git a/examples/reallylong.go b/examples/reallylong.go index 00c371e..3a8aed1 100644 --- a/examples/reallylong.go +++ b/examples/reallylong.go @@ -1,7 +1,9 @@ package main -import "log" +import ( + log "git.staur.ca/stobbsm/simplelog" +) func ReallyLongRuneset() { - log.Println("Really long runeset") + log.Info("examples.ReallyLongRuneset").Msg("Really long runeset") } diff --git a/tind_test.go b/tind_test.go index 086e00e..9beafd8 100644 --- a/tind_test.go +++ b/tind_test.go @@ -1,9 +1,10 @@ package tind import ( - log "git.staur.ca/stobbsm/simplelog" "testing" "time" + + log "git.staur.ca/stobbsm/simplelog" ) func Test_GenTinD_With_Defaults(t *testing.T) { @@ -64,10 +65,14 @@ func checkCollisions(tindSize int) { } // Print a message every 2000000 iterations saying we are still working if iters%2000000 == 0 { - log.Info("test.checkCollisions").uint64("iterations", iters).Int("size", tindSize).Msg("Still no collions") + log.Info("test.checkCollisions").Uint64("iterations", iters).Int("size", tindSize).Msg("Still no collions") } } - log.Info("test.checkCollisions").uint64("iterations", iters).Int("size", tindSize).Msg("Collision found", time.Since(start)) + log.Info("test.checkCollisions"). + Uint64("iterations", iters). + Int("size", tindSize). + Dur("duration", time.Since(start)). + Msg("Collision found") } func Test_GenerateConfigFromByteSlice(t *testing.T) {