Files
pg-bkup/utils/logger.go

62 lines
1.5 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"
"os"
"time"
)
// Info message
func Info(msg string, args ...any) {
2024-10-05 10:39:08 +02:00
var currentTime = time.Now().Format("2006/01/02 15:04:05")
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
fmt.Printf("%s INFO: %s\n", currentTime, msg)
} else {
fmt.Printf("%s INFO: %s\n", currentTime, formattedMessage)
}
}
// Warn Warning message
func Warn(msg string, args ...any) {
2024-10-05 10:39:08 +02:00
var currentTime = time.Now().Format("2006/01/02 15:04:05")
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
fmt.Printf("%s WARN: %s\n", currentTime, msg)
} else {
fmt.Printf("%s WARN: %s\n", currentTime, formattedMessage)
}
}
// Error error message
func Error(msg string, args ...any) {
2024-10-05 10:39:08 +02:00
var currentTime = time.Now().Format("2006/01/02 15:04:05")
2024-08-04 01:20:30 +02:00
formattedMessage := fmt.Sprintf(msg, args...)
if len(args) == 0 {
fmt.Printf("%s ERROR: %s\n", currentTime, msg)
} else {
fmt.Printf("%s ERROR: %s\n", currentTime, formattedMessage)
}
}
func Fatal(msg string, args ...any) {
2024-10-05 10:39:08 +02:00
var currentTime = time.Now().Format("2006/01/02 15:04:05")
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 {
fmt.Printf("%s ERROR: %s\n", currentTime, msg)
2024-09-10 22:59:28 +02:00
NotifyError(msg)
2024-08-04 01:20:30 +02:00
} else {
fmt.Printf("%s ERROR: %s\n", currentTime, 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)
}