From 20d92dd7c65a491a0dc8f3b3fb8e10295bb9cd94 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Wed, 18 Dec 2024 20:33:01 +0500 Subject: [PATCH] Create a logger util --- utils/logger.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 utils/logger.go diff --git a/utils/logger.go b/utils/logger.go new file mode 100644 index 000000000..de92d3c5c --- /dev/null +++ b/utils/logger.go @@ -0,0 +1,32 @@ +package utils + +import ( + "log" + "os" +) + +type Logger struct { + infoLogger *log.Logger + errorLogger *log.Logger + debugLogger *log.Logger +} + +func NewLogger() *Logger { + return &Logger{ + infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), + errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), + debugLogger: log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), + } +} + +func (l *Logger) Info(format string, v ...interface{}) { + l.infoLogger.Printf(format, v...) +} + +func (l *Logger) Error(format string, v ...interface{}) { + l.errorLogger.Printf(format, v...) +} + +func (l *Logger) Debug(format string, v ...interface{}) { + l.debugLogger.Printf(format, v...) +}