58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
// Package helpers provides useful helper structures for KermaGo
|
|
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
/*
|
|
A Logger is a helper used for logging messages to stdout and stderr
|
|
*/
|
|
type Logger struct{}
|
|
|
|
/*
|
|
Debug logs a debug message to stdout if the KERMA_DEBUG environment variable is set to true
|
|
*/
|
|
func (l *Logger) Debug(msg string) {
|
|
if os.Getenv("KERMA_DEBUG") == "true" {
|
|
t := time.Now()
|
|
_, _ = fmt.Fprintln(os.Stdout, t.Format(time.RFC1123)+" [DEBUG] "+msg)
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
Info logs an info message to stdout
|
|
*/
|
|
func (l *Logger) Info(msg string) {
|
|
t := time.Now()
|
|
_, _ = fmt.Fprintln(os.Stdout, t.Format(time.RFC1123)+" [INFO] "+msg)
|
|
}
|
|
|
|
/*
|
|
Warn logs a warning message to stderr
|
|
*/
|
|
func (l *Logger) Warn(msg string) {
|
|
t := time.Now()
|
|
_, _ = fmt.Fprintln(os.Stderr, t.Format(time.RFC1123)+" [WARN] "+msg)
|
|
}
|
|
|
|
/*
|
|
Error logs an error message to stderr
|
|
*/
|
|
func (l *Logger) Error(msg string) {
|
|
t := time.Now()
|
|
_, _ = fmt.Fprintln(os.Stderr, t.Format(time.RFC1123)+" [ERROR] "+msg)
|
|
}
|
|
|
|
/*
|
|
Fatal logs a fatal message to stderr and terminates the application
|
|
*/
|
|
func (l *Logger) Fatal(msg string) {
|
|
t := time.Now()
|
|
_, _ = fmt.Fprintln(os.Stderr, t.Format(time.RFC1123)+" [FATAL] "+msg)
|
|
os.Exit(1)
|
|
}
|