-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DetermineLogLevel function and tests for logging
**Added:** - `DetermineLogLevel` function in `loginfo.go` to determine the log level from a given string. - Test cases for `DetermineLogLevel` function in `loginfo_test.go` using table-driven tests. **Changed:** - Bumped go version to `1.22` in `go.mod` and `go.sum` files.
- Loading branch information
Showing
7 changed files
with
116 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/l50/goutils/v2 | ||
|
||
go 1.21 | ||
go 1.22 | ||
|
||
require ( | ||
github.com/bitfield/script v0.22.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package logging_test | ||
|
||
import ( | ||
"log/slog" | ||
"testing" | ||
|
||
"github.com/l50/goutils/v2/logging" | ||
) | ||
|
||
func TestDetermineLogLevel(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input string | ||
expected slog.Level | ||
}{ | ||
{ | ||
name: "Debug level", | ||
input: "debug", | ||
expected: slog.LevelDebug, | ||
}, | ||
{ | ||
name: "Info level", | ||
input: "info", | ||
expected: slog.LevelInfo, | ||
}, | ||
{ | ||
name: "Warn level", | ||
input: "warn", | ||
expected: slog.LevelWarn, | ||
}, | ||
{ | ||
name: "Error level", | ||
input: "error", | ||
expected: slog.LevelError, | ||
}, | ||
{ | ||
name: "Default level", | ||
input: "unknown", | ||
expected: slog.LevelInfo, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := logging.DetermineLogLevel(tc.input) | ||
if result != tc.expected { | ||
t.Errorf("DetermineLogLevel(%s) = %v, want %v", tc.input, result, tc.expected) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module magefile | ||
|
||
go 1.21 | ||
go 1.22 | ||
|
||
toolchain go1.22.0 | ||
|
||
require ( | ||
github.com/fatih/color v1.16.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters