Skip to content

Commit ff12394

Browse files
committed
♻️ refactor: add new slogger functions #2
1 parent d4854ad commit ff12394

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/slogger/field.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ func String(key, val string) Field {
151151
return Field{key: key, typ: StringType, strVal: val}
152152
}
153153

154+
// Stringf constructs a Field carrying a formatted string value.
155+
//
156+
// Parameters:
157+
// - `key`: the field name
158+
// - `format`: the format string
159+
// - `args`: the arguments to format
160+
//
161+
// Returns:
162+
//
163+
// a Field of type StringType.
164+
func Stringf(key, format string, args ...any) Field {
165+
return Field{key: key, typ: StringType, strVal: fmt.Sprintf(format, args...)}
166+
}
167+
154168
// Bool constructs a Field carrying a bool value.
155169
//
156170
// Parameters:

pkg/slogger/global.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func Error(msg string, fields ...Field) {
5858
GlobalLogger().dispatch(ErrorLevel, msg, fields...)
5959
}
6060

61+
// Fatal logs a FATAL-level message via the global logger.
62+
func Fatal(msg string, fields ...Field) {
63+
GlobalLogger().dispatch(FatalLevel, msg, fields...)
64+
}
65+
6166
// Tracef logs a TRACE-level formatted message via the global logger.
6267
func Tracef(format string, args ...any) {
6368
GlobalLogger().Tracef(format, args...)
@@ -83,6 +88,11 @@ func Errorf(format string, args ...any) {
8388
GlobalLogger().Errorf(format, args...)
8489
}
8590

91+
// Fatalf logs a FATAL-level formatted message via the global logger.
92+
func Fatalf(format string, args ...any) {
93+
GlobalLogger().Fatalf(format, args...)
94+
}
95+
8696
// GlobalWithContextFields returns a new context that carries the provided fields for
8797
// use with the global logger.
8898
func GlobalWithContextFields(ctx context.Context, fields ...Field) context.Context {

0 commit comments

Comments
 (0)