-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance logging with caller information and add corresponding t…
…ests - Add `path/filepath` and `runtime` imports - Modify logging functions to include caller information - Add `addCallerInfo` method to append file and line number to log messages - Create a new test file `slog_test.go` - Add tests for `addCallerInfo` method to verify it appends caller information correctly Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
2 changed files
with
46 additions
and
8 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
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,27 @@ | ||
package slog | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAddCallerInfo(t *testing.T) { | ||
manager := New() | ||
|
||
tests := []struct { | ||
name string | ||
msg string | ||
}{ | ||
{"Test with simple message", "This is a test message"}, | ||
{"Test with empty message", ""}, | ||
{"Test with special characters", "Special characters !@#$%^&*()"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := manager.addCallerInfo(tt.msg) | ||
if result == tt.msg { | ||
t.Errorf("Expected caller info to be added, but got: %s", result) | ||
} | ||
}) | ||
} | ||
} |