From 3c2395568e9dd741b2b062f78f119f1b317707df Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Sun, 7 Apr 2024 11:38:55 -0600 Subject: [PATCH] moving log to simplelog --- config.go | 4 ++-- go.mod | 12 +++++++++++- go.sum | 20 ++++++++++++++++++++ tind_test.go | 8 ++++---- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 go.sum diff --git a/config.go b/config.go index 5bf0912..fc71e37 100644 --- a/config.go +++ b/config.go @@ -3,7 +3,7 @@ package tind import ( "crypto/rand" "errors" - "log" + log "git.staur.ca/stobbsm/simplelog" ) // Config is a configuration for generating and working with TinD id's of @@ -121,7 +121,7 @@ func (c *Config) Gen() TinD { runes := make([]rune, c.size) _, err := rand.Read(bytes) if err != nil { - log.Fatalln(err) + log.Fatal("config.Gen").Err(err).Send() } // Make sure each byte fits the rune so it can be encoded and decoded for i := 0; i < c.size; i++ { diff --git a/go.mod b/go.mod index 8bee0ee..5d0e922 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,13 @@ module git.staur.ca/stobbsm/tind -go 1.22 +go 1.22.1 + +require git.staur.ca/stobbsm/simplelog v0.0.0-20240407172718-26a74495adc9 + +require ( + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rs/zerolog v1.32.0 // indirect + golang.org/x/sys v0.15.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fd650da --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +git.staur.ca/stobbsm/simplelog v0.0.0-20240407172718-26a74495adc9 h1:A3XQw1dxgNqAHWUzzz2zdAV8bWHIEvxRgF+JYo4/elc= +git.staur.ca/stobbsm/simplelog v0.0.0-20240407172718-26a74495adc9/go.mod h1:ruZaa6TgS/lJ4lC78nXHm4sb+zftJ0IwsEN7mvaksc8= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= +github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/tind_test.go b/tind_test.go index 23f42e5..086e00e 100644 --- a/tind_test.go +++ b/tind_test.go @@ -1,7 +1,7 @@ package tind import ( - "log" + log "git.staur.ca/stobbsm/simplelog" "testing" "time" ) @@ -53,7 +53,7 @@ func checkCollisions(tindSize int) { var iters uint64 start := time.Now() - log.Printf("Starting check with size %d", tindSize) + log.Info("test.checkCollisions").Int("size", tindSize).Msg("Starting collision check") for !collided { iters++ nt := tc.Gen() @@ -64,10 +64,10 @@ func checkCollisions(tindSize int) { } // Print a message every 2000000 iterations saying we are still working if iters%2000000 == 0 { - log.Printf("Still no collions on size %d after %d iterations", tindSize, iters) + log.Info("test.checkCollisions").uint64("iterations", iters).Int("size", tindSize).Msg("Still no collions") } } - log.Printf("Collision found after %v and %d iterations with size of %d", time.Since(start), iters, tindSize) + log.Info("test.checkCollisions").uint64("iterations", iters).Int("size", tindSize).Msg("Collision found", time.Since(start)) } func Test_GenerateConfigFromByteSlice(t *testing.T) {