81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Logger interface {
|
|
Debug(v ...any)
|
|
Info(v ...any)
|
|
Warning(v ...any)
|
|
Error(v ...any)
|
|
Fatal(v ...any)
|
|
Debugf(format string, v ...any)
|
|
Infof(format string, v ...any)
|
|
Warningf(format string, v ...any)
|
|
Errorf(format string, v ...any)
|
|
Fatalf(format string, v ...any)
|
|
}
|
|
|
|
type ConsoleLogger struct {
|
|
logger *log.Logger
|
|
}
|
|
|
|
func NewConsoleLogger() *ConsoleLogger {
|
|
return &ConsoleLogger{
|
|
logger: log.New(os.Stdout, "", log.LstdFlags),
|
|
}
|
|
}
|
|
|
|
// Info logs an informational message.
|
|
func (c *ConsoleLogger) Debug(v ...any) {
|
|
c.logger.Println("[DEBUG]: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
// Info logs an informational message.
|
|
func (c *ConsoleLogger) Info(v ...any) {
|
|
c.logger.Println("[INFO]: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
// Info logs an informational message.
|
|
func (c *ConsoleLogger) Warning(v ...any) {
|
|
c.logger.Println("[INFO]: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
// Info logs an informational message.
|
|
func (c *ConsoleLogger) Error(v ...any) {
|
|
c.logger.Println("[ERROR]: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
// Info logs an informational message.
|
|
func (c *ConsoleLogger) Fatal(v ...any) {
|
|
c.logger.Fatal("[FATAL]: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
// Debugf logs a formatted debug message.
|
|
func (c *ConsoleLogger) Debugf(format string, v ...any) {
|
|
c.logger.Printf("[DEBUG]: "+format, v...)
|
|
}
|
|
|
|
// Infof logs a formatted informational message.
|
|
func (c *ConsoleLogger) Infof(format string, v ...any) {
|
|
c.logger.Printf("[INFO]: "+format, v...)
|
|
}
|
|
|
|
// Warningf logs a formatted warning message.
|
|
func (c *ConsoleLogger) Warningf(format string, v ...any) {
|
|
c.logger.Printf("[WARNING]: "+format, v...)
|
|
}
|
|
|
|
// Errorf logs a formatted error message.
|
|
func (c *ConsoleLogger) Errorf(format string, v ...any) {
|
|
c.logger.Printf("[ERROR]: "+format, v...)
|
|
}
|
|
|
|
// Fatalf logs a formatted fatal message and exits the program.
|
|
func (c *ConsoleLogger) Fatalf(format string, v ...any) {
|
|
c.logger.Fatalf("[FATAL]: "+format, v...)
|
|
}
|