feat: add Fatalf logging method to Logger interface and ServiceLogger

- Introduced Fatalf method in Logger interface for logging fatal messages with formatted content.
- Implemented Fatalf in ServiceLogger to log fatal messages and exit the program, enhancing error handling capabilities.
This commit is contained in:
Marvin Zhang
2024-12-23 13:15:18 +08:00
parent afe21b7ca0
commit bdc347aef7
2 changed files with 8 additions and 0 deletions

View File

@@ -13,4 +13,7 @@ type Logger interface {
// Errorf logs a formatted error message.
Errorf(format string, args ...interface{})
// Fatalf logs a formatted fatal message.
Fatalf(format string, args ...interface{})
}

View File

@@ -37,6 +37,11 @@ func (l *ServiceLogger) Debugf(format string, args ...interface{}) {
log.Debugf(l.getFormat(format), args...)
}
// Fatalf logs a fatal message with formatted content and exits the program.
func (l *ServiceLogger) Fatalf(format string, args ...interface{}) {
log.Fatalf(l.getFormat(format), args...)
}
func (l *ServiceLogger) getFormat(format string) string {
return fmt.Sprintf("[%s] %s", l.prefix, format)
}