-
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.
Add back some deprecated logging functions
Change-Id: Ie213e668a927342c31deb398f19d8982b1a2169a
- Loading branch information
Showing
2 changed files
with
115 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//nolint:staticcheck | ||
package zlog | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
// Debugf ... | ||
// Deprecated: this function will be removed in the future, please use Debug instead. | ||
func Debugf(format string, args ...any) { | ||
l := Default() | ||
if l.Enabled(nil, slog.LevelDebug) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, l, slog.LevelDebug, msg, nil) | ||
} | ||
} | ||
|
||
// Infof ... | ||
// Deprecated: this function will be removed in the future, please use Info instead. | ||
func Infof(format string, args ...any) { | ||
l := Default() | ||
if l.Enabled(nil, slog.LevelInfo) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, l, slog.LevelInfo, msg, nil) | ||
} | ||
} | ||
|
||
// Warnf ... | ||
// Deprecated: this function will be removed in the future, please use Warn instead. | ||
func Warnf(format string, args ...any) { | ||
l := Default() | ||
if l.Enabled(nil, slog.LevelWarn) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, l, slog.LevelWarn, msg, nil) | ||
} | ||
} | ||
|
||
// Errorf ... | ||
// Deprecated: this function will be removed in the future, please use Error instead. | ||
func Errorf(format string, args ...any) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, Default(), slog.LevelError, msg, nil) | ||
} | ||
|
||
// Fatalf is equivalent to Errorf() followed by a call to os.Exit(1). | ||
// Deprecated: this function will be removed in the future, please use Fatal instead. | ||
func Fatalf(format string, args ...any) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, Default(), slog.LevelError, msg, nil) | ||
os.Exit(1) | ||
} | ||
|
||
// Print uses [fmt.Sprint] to log a message at InfoLevel, or level | ||
// detected from args, if it's enabled. | ||
// It has same signature with [log.Print]. | ||
// | ||
// Deprecated: this function will be removed in the future, please use | ||
// Logger or the leveled logging functions. | ||
func Print(args ...any) { | ||
l := Default() | ||
level := slog.LevelInfo | ||
if len(args) > 0 { | ||
s, _ := args[0].(string) | ||
level = detectLevel(s) | ||
} | ||
if l.Enabled(nil, level) { | ||
msg := fmt.Sprint(args...) | ||
_log(nil, 0, l, level, msg, nil) | ||
} | ||
} | ||
|
||
// Printf uses [fmt.Sprintf] to log a message at InfoLevel, or level | ||
// detected from args, if it's enabled. | ||
// It has same signature with [log.Printf]. | ||
// | ||
// Deprecated: this function will be removed in the future, please use | ||
// Logger or the leveled logging functions. | ||
func Printf(format string, args ...any) { | ||
l := Default() | ||
level := detectLevel(format) | ||
if l.Enabled(nil, level) { | ||
msg := formatMessage(format, args) | ||
_log(nil, 0, l, level, msg, nil) | ||
} | ||
} | ||
|
||
// Println uses [fmt.Sprintln] to log a message at InfoLevel, or level | ||
// detected from args, if it's enabled. | ||
// It has same signature with [log.Println]. | ||
// | ||
// Deprecated: this function will be removed in the future, please use | ||
// Logger or the leveled logging functions. | ||
func Println(args ...any) { | ||
l := Default() | ||
level := slog.LevelInfo | ||
if len(args) > 0 { | ||
s, _ := args[0].(string) | ||
level = detectLevel(s) | ||
} | ||
if l.Enabled(nil, level) { | ||
msg := fmt.Sprintln(args...) | ||
_log(nil, 0, l, level, msg, nil) | ||
} | ||
} | ||
|
||
func formatMessage(format string, args []any) string { | ||
if len(args) == 0 { | ||
return format | ||
} | ||
return fmt.Sprintf(format, args...) | ||
} |
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