From bdc347aef78afd0b33ea2e3045b3877b3289d442 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Mon, 23 Dec 2024 13:15:18 +0800 Subject: [PATCH] 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. --- core/interfaces/logger.go | 3 +++ core/utils/log.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/core/interfaces/logger.go b/core/interfaces/logger.go index dce1ee6d..d8a92486 100644 --- a/core/interfaces/logger.go +++ b/core/interfaces/logger.go @@ -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{}) } diff --git a/core/utils/log.go b/core/utils/log.go index babda4ac..8852897b 100644 --- a/core/utils/log.go +++ b/core/utils/log.go @@ -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) }