From d79bef677471f1122b579a6fb4aff2e1f517308d Mon Sep 17 00:00:00 2001 From: Nathan Barley Date: Wed, 18 Jan 2023 01:05:42 +0000 Subject: [PATCH 1/4] Update 'go.mod' --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 554c615..c880780 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.zio.sh/astra/logger -go 1.16 +go 1.18 require ( github.com/fatih/color v1.10.0 From c7a3e64167f14e9c23bc03a0367d4d524acdee56 Mon Sep 17 00:00:00 2001 From: Nathan Barley Date: Wed, 8 Feb 2023 13:04:33 +0000 Subject: [PATCH 2/4] Delete 'logger_legacy_test.go' --- logger_legacy_test.go | 158 ------------------------------------------ 1 file changed, 158 deletions(-) delete mode 100644 logger_legacy_test.go diff --git a/logger_legacy_test.go b/logger_legacy_test.go deleted file mode 100644 index 1ac038b..0000000 --- a/logger_legacy_test.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright © 2021 Kris Nóva -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ---------------------------------------------------------------------------- -// -// Legacy Regression tests for 0.1.0 -// -// Note: @christopherhein added these tests and I am unsure if Amazon -// is still using the old io.Writer append() convention. -// Either way, I am keeping legacy (deprecated) support for it. -// -// All of these regression tests should still pass. -// -// ---------------------------------------------------------------------------- - -package logger - -import ( - "bytes" - "fmt" - "regexp" - "testing" -) - -const ( - format = "%v, %v, %v, all eyes on me!" - formatExp = `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.* \[%s\] \d, \d, \d, all eyes on me!` - formatWOTimeExp = `\[%s\] \d, \d, \d, all eyes on me!` -) - -var ( - a = []interface{}{1, 2, 3} -) - -func TestMain(m *testing.M) { - TestMode = true - m.Run() -} - -func TestAlwaysLegacy(t *testing.T) { - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreAlways)) - g := captureLoggerOutput(Always, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Always should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestCriticalLegacy(t *testing.T) { - Level = 1 - - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreCritical)) - g := captureLoggerOutput(Critical, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Critical should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestInfoLegacy(t *testing.T) { - Level = 3 - - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreInfo)) - g := captureLoggerOutput(Info, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Info should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestSuccessLegacy(t *testing.T) { - Level = 3 - - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreSuccess)) - g := captureLoggerOutput(Success, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Success should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestDebugLegacy(t *testing.T) { - Level = 4 - - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreDebug)) - g := captureLoggerOutput(Debug, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Info should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestWarningLegacy(t *testing.T) { - Level = 2 - - e, err := regexp.Compile(fmt.Sprintf(formatExp, PreWarning)) - g := captureLoggerOutput(Warning, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Info should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -func TestWithoutTimestampsLegacy(t *testing.T) { - Timestamps = false - e, err := regexp.Compile(fmt.Sprintf(formatWOTimeExp, PreAlways)) - g := captureLoggerOutput(Always, format, a) - - if err != nil { - t.Fatalf("Failed to compile regexp '%v': %v", e.String(), err) - } - - if !e.MatchString(g) { - t.Fatalf("Always should produce a pattern '%v' but produces: %v", e.String(), g) - } -} - -// captureLoggerOutput is used to test the log functions -func captureLoggerOutput(l LoggerFunc, format string, a []interface{}) string { - b := new(bytes.Buffer) - l(format, append(a, b)...) - return b.String() -} From 4512aae71ca70169f1ec4b71cbeb5e9d5d4c106b Mon Sep 17 00:00:00 2001 From: Nathan Barley Date: Wed, 8 Feb 2023 13:04:36 +0000 Subject: [PATCH 3/4] Delete 'logger_legacy.go' --- logger_legacy.go | 108 ----------------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 logger_legacy.go diff --git a/logger_legacy.go b/logger_legacy.go deleted file mode 100644 index ea3b711..0000000 --- a/logger_legacy.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright © 2021 Kris Nóva -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logger - -import ( - "io" - "sync" -) - -// Legacy Logic for 0.1.0 -// -// Here we store the legacy (0.1.0) compatible configuration options -// that will eventually be deprecated. -// -var ( - - // Timestamps are used to toggle timestamps - // deprecated - Timestamps = true - - // TestMode is used for running - // the regression tests. - // deprecated - TestMode = false - - // Color is no longer used - // deprecated - Color = true - - // Level is the legacy log level - // - // 0 (Least verbose) - // 1 - // 2 - // 3 - // 4 (Most verbose) - // - // deprecated - Level = -1 -) - -var ( - testRaceMutex = sync.Mutex{} - annoyed = false -) - -// checkDeprecatedValues is a singleton -// that will only execute once. -// This will convert the legacy logger.Level -// to the new logger.BitwiseLevel -// -// LogEverything = -func checkDeprecatedValues() { - testRaceMutex.Lock() - defer testRaceMutex.Unlock() - if Level != -1 { - if !annoyed { - Deprecated("********") - Deprecated("***") - Deprecated("*") - Deprecated("logger.Level is deprecated. Use logger.BitwiseLevel") - Deprecated("*") - Deprecated("***") - Deprecated("********") - annoyed = true - } - if Level == 4 { - BitwiseLevel = LogDeprecated | LogAlways | LogSuccess | LogCritical | LogWarning | LogInfo | LogDebug - } else if Level == 3 { - BitwiseLevel = LogDeprecated | LogAlways | LogSuccess | LogCritical | LogWarning | LogInfo - } else if Level == 2 { - BitwiseLevel = LogDeprecated | LogAlways | LogSuccess | LogCritical | LogWarning - } else if Level == 1 { - BitwiseLevel = LogDeprecated | LogAlways | LogSuccess | LogCritical - } else if Level == 0 { - BitwiseLevel = LogDeprecated | LogAlways | LogSuccess - } else { - BitwiseLevel = LogDeprecated | LogEverything - } - } -} - -// legacyFindWriter will check if there is an io.Writer -// appended to the end of the arguments passed to the logger. -// -// deprecated -func legacyFindWriter(a ...interface{}) []interface{} { - if n := len(a); n > 0 { - // extract an io.Writer at the end of a - if newWriter, ok := a[n-1].(io.Writer); ok { - Writer = newWriter - a = a[0 : n-1] - } - } - return a -} From 181161616c5147d0bab15a9cefae48df3ad1c634 Mon Sep 17 00:00:00 2001 From: Astra Date: Thu, 31 Aug 2023 17:57:00 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6eb9e79..6d679af 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - [2017] Originally ported from it's [original location](https://github.com/kubicorn/kubicorn/tree/master/pkg/logger) in the Kubicorn code base. - [2021] Refactored to support custom `io.Writer`'s -
+
## Install