Archived
2
0
This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
kerma/helpers/logger.go

58 lines
1.2 KiB
Go
Raw Normal View History

2023-03-02 14:28:43 +00:00
// 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)
}