Files
pg-bkup/utils/logger.go

63 lines
1.3 KiB
Go
Raw Normal View History

2024-09-10 22:59:28 +02:00
// Package utils /
/*****
@author Jonas Kaninda
@license MIT License <https://opensource.org/licenses/MIT>
@Copyright © 2024 Jonas Kaninda
**/
2024-08-04 01:20:30 +02:00
package utils
import (
"fmt"
"log"
2024-08-04 01:20:30 +02:00
"os"
)
// Info message
func Info(msg string, args ...any) {
log.SetOutput(os.Stdout)
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
log.Printf("INFO: %s\n", msg)
2024-08-04 01:20:30 +02:00
} else {
log.Printf("INFO: %s\n", formattedMessage)
2024-08-04 01:20:30 +02:00
}
}
// Warn a Warning message
2024-08-04 01:20:30 +02:00
func Warn(msg string, args ...any) {
log.SetOutput(os.Stdout)
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
log.Printf("WARN: %s\n", msg)
2024-08-04 01:20:30 +02:00
} else {
log.Printf("WARN: %s\n", formattedMessage)
2024-08-04 01:20:30 +02:00
}
}
// Error error message
func Error(msg string, args ...any) {
log.SetOutput(os.Stdout)
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
log.Printf("ERROR: %s\n", msg)
2024-08-04 01:20:30 +02:00
} else {
log.Printf("ERROR: %s\n", formattedMessage)
2024-08-04 01:20:30 +02:00
}
}
func Fatal(msg string, args ...any) {
log.SetOutput(os.Stdout)
2024-08-04 01:20:30 +02:00
// Fatal logs an error message and exits the program.
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
log.Printf("ERROR: %s\n", msg)
2024-09-10 22:59:28 +02:00
NotifyError(msg)
2024-08-04 01:20:30 +02:00
} else {
log.Printf("ERROR: %s\n", formattedMessage)
2024-09-10 22:59:28 +02:00
NotifyError(formattedMessage)
2024-08-04 01:20:30 +02:00
}
2024-09-10 22:59:28 +02:00
2024-08-04 01:20:30 +02:00
os.Exit(1)
}