-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for enforcing log messages are static by requiring the use of string literals or constants. Fixes #17.
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 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
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,31 @@ | ||
package static_msg | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
) | ||
|
||
const constMsg = "msg" | ||
|
||
var varMsg = "msg" | ||
|
||
func tests() { | ||
ctx := context.Background() | ||
|
||
slog.Log(ctx, slog.LevelInfo, "msg") | ||
slog.Debug("msg") | ||
slog.DebugContext(ctx, "msg") | ||
|
||
slog.Log(ctx, slog.LevelInfo, constMsg) | ||
slog.Debug(constMsg) | ||
slog.DebugContext(ctx, constMsg) | ||
|
||
slog.Log(ctx, slog.LevelInfo, fmt.Sprintf("msg")) // want `messages should be string literals or constants` | ||
slog.Debug(fmt.Sprintf("msg")) // want `messages should be string literals or constants` | ||
slog.DebugContext(ctx, fmt.Sprintf("msg")) // want `messages should be string literals or constants` | ||
|
||
slog.Log(ctx, slog.LevelInfo, varMsg) // want `messages should be string literals or constants` | ||
slog.Debug(varMsg) // want `messages should be string literals or constants` | ||
slog.DebugContext(ctx, varMsg) // want `messages should be string literals or constants` | ||
} |