From e21fb8a614dfee2af59de4d63377bb06b66b0d65 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 14 Oct 2022 22:23:42 -0700 Subject: [PATCH] make pass gofumpt --- LICENSE | 2 +- log/log.go | 22 ++++++++-------------- log/log_test.go | 3 +-- ws/server.go | 2 +- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/LICENSE b/LICENSE index 73f6e36..7b94222 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2019-2021 by Tai Groot +Copyright (C) 2019-2022 by Tai Groot Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. diff --git a/log/log.go b/log/log.go index 61ac38c..71b5092 100644 --- a/log/log.go +++ b/log/log.go @@ -26,18 +26,12 @@ func init() { } func (c *Client) logStdErr() { - for { - select { - case e, more := <-c.writer: - if e.level >= c.LogLevel { - fmt.Fprintf(os.Stderr, "%s\t%s\t%s\t%s\n", e.Timestamp.String(), e.Level, e.Output, e.File) - } - if !more { - stderrFinished <- true - return - } + for e := range c.writer { + if e.level >= c.LogLevel { + fmt.Fprintf(os.Stderr, "%s\t%s\t%s\t%s\n", e.Timestamp.String(), e.Level, e.Output, e.File) } } + stderrFinished <- true } func CreateClient() *Client { @@ -61,7 +55,7 @@ func Flush() { func (c *Client) Destroy() error { var otherClients []*Client if !c.initialized { - panic(errors.New("Cannot delete uninitialized client, did you use CreateClient?")) + panic(errors.New("cannot delete uninitialized client, did you use CreateClient?")) } sliceTex.Lock() c.writer = nil @@ -78,7 +72,7 @@ func (c *Client) Destroy() error { func (c *Client) GetLogLevel() Level { if !c.initialized { - panic(errors.New("Cannot get level for uninitialized client, use CreateClient instead")) + panic(errors.New("cannot get level for uninitialized client, use CreateClient instead")) } return c.LogLevel } @@ -109,14 +103,14 @@ func SetLogLevel(level Level) { // SetLogLevel set log level of logger func (c *Client) SetLogLevel(level Level) { if !c.initialized { - panic(errors.New("Cannot set level for uninitialized client, use CreateClient instead")) + panic(errors.New("cannot set level for uninitialized client, use CreateClient instead")) } c.LogLevel = level } func (c *Client) Get() Entry { if !c.initialized { - panic(errors.New("Cannot get logs for uninitialized client, did you use CreateClient?")) + panic(errors.New("cannot get logs for uninitialized client, did you use CreateClient?")) } return <-c.writer } diff --git a/log/log_test.go b/log/log_test.go index 7c2fcf6..472f1ce 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -55,8 +55,7 @@ func BenchmarkDebugSerial(b *testing.B) { // Trace ensure logs come out in the right order func TestOrder(t *testing.T) { testString := "Testing trace: " - var c *Client - c = CreateClient() + c := CreateClient() c.SetLogLevel(LTrace) for i := 0; i < 5000; i++ { diff --git a/ws/server.go b/ws/server.go index fdf52d8..6cfe5ec 100644 --- a/ws/server.go +++ b/ws/server.go @@ -25,7 +25,7 @@ func LogSocketHandler(w http.ResponseWriter, r *http.Request) { logger.Info("Websocket client attached.") for { logEvent := lc.Get() - logJSON, err := json.Marshal(logEvent) + logJSON, _ := json.Marshal(logEvent) err = c.WriteMessage(websocket.TextMessage, logJSON) if err != nil { logger.Error("write:", err)