阶段十:完成 Go 基础包注释基线清零
This commit is contained in:
1 parent
ea1f2ec430
commit
d1a165f897
14 files changed
+135
-924
No files matched your search
@@ -8,14 +8,18 @@ import (
|
||||
)
|
||||
|
||||
// Level is the process-wide dynamic slog level.
|
||||
// Level 保存Level,供当前处理流程使用
|
||||
var Level slog.LevelVar
|
||||
|
||||
// init 负责init相关处理。
|
||||
func init() {
|
||||
Level.Set(slog.LevelInfo)
|
||||
}
|
||||
|
||||
// NewLogger creates a slog logger wired to the dynamic Level.
|
||||
// NewLogger 负责NewLogger相关处理。
|
||||
func NewLogger(w io.Writer, format string) *slog.Logger {
|
||||
// opts 保存opts,供当前处理流程使用
|
||||
opts := &slog.HandlerOptions{Level: &Level}
|
||||
if strings.EqualFold(strings.TrimSpace(format), "json") {
|
||||
return slog.New(slog.NewJSONHandler(w, opts))
|
||||
@@ -24,7 +28,9 @@ func NewLogger(w io.Writer, format string) *slog.Logger {
|
||||
}
|
||||
|
||||
// SetLevel updates the process-wide log level.
|
||||
// SetLevel 设置Level。
|
||||
func SetLevel(raw string) error {
|
||||
// lv、err 保存lv、err,供当前处理流程使用
|
||||
lv, err := ParseLevel(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -34,6 +40,7 @@ func SetLevel(raw string) error {
|
||||
}
|
||||
|
||||
// ParseLevel parses debug/info/warn/error.
|
||||
// ParseLevel 解析Level。
|
||||
func ParseLevel(raw string) (slog.Level, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||
case "", "info":
|
||||
|
||||
Reference in new issue
Block a user