-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement logging interfaces and service logger
- Added Logger interface in core/interfaces/logger.go for standardized logging methods (Debugf, Infof, Warnf, Errorf). - Introduced ServiceLogger in core/utils/log.go, which prefixes log messages with the service name for better context. - Implemented logging methods in ServiceLogger to utilize the apex/log package for structured logging.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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,16 @@ | ||
package interfaces | ||
|
||
// Logger interface for reporting informational and warning messages. | ||
type Logger interface { | ||
// Debugf logs a formatted debugging message. | ||
Debugf(format string, args ...interface{}) | ||
|
||
// Infof logs a formatted informational message. | ||
Infof(format string, args ...interface{}) | ||
|
||
// Warnf logs a formatted warning message. | ||
Warnf(format string, args ...interface{}) | ||
|
||
// Errorf logs a formatted error message. | ||
Errorf(format string, args ...interface{}) | ||
} |
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,42 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"github.com/apex/log" | ||
) | ||
|
||
// ServiceLogger represents a logger with a specific service prefix. | ||
type ServiceLogger struct { | ||
prefix string | ||
} | ||
|
||
// NewServiceLogger creates a new logger with the given service name as a prefix. | ||
func NewServiceLogger(serviceName string) *ServiceLogger { | ||
return &ServiceLogger{ | ||
prefix: serviceName, | ||
} | ||
} | ||
|
||
// Infof logs an informational message with formatted content. | ||
func (l *ServiceLogger) Infof(format string, args ...interface{}) { | ||
log.Infof(l.getFormat(format), args...) | ||
} | ||
|
||
// Warnf logs a warning message with formatted content. | ||
func (l *ServiceLogger) Warnf(format string, args ...interface{}) { | ||
log.Warnf(l.getFormat(format), args...) | ||
} | ||
|
||
// Errorf logs an error message with formatted content. | ||
func (l *ServiceLogger) Errorf(format string, args ...interface{}) { | ||
log.Errorf(l.getFormat(format), args...) | ||
} | ||
|
||
// Debugf logs a debug message with formatted content. | ||
func (l *ServiceLogger) Debugf(format string, args ...interface{}) { | ||
log.Debugf(l.getFormat(format), args...) | ||
} | ||
|
||
func (l *ServiceLogger) getFormat(format string) string { | ||
return fmt.Sprintf("[%s] %s", l.prefix, format) | ||
} |