44 lines
865 B
Go
44 lines
865 B
Go
// Logging module
|
|
//
|
|
// This module is a wrapper around the built-in `log` package
|
|
// and adds more control around if and how logging shows up
|
|
// in the code.
|
|
package logging
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Logger struct {
|
|
Info log.Logger
|
|
Error log.Logger
|
|
}
|
|
|
|
var Log Logger
|
|
|
|
// Configures the loggers and initializes each logging level's instance.
|
|
//
|
|
// This should be run once and before any logging is done.
|
|
func ConfigureLogger() {
|
|
Log = Logger{
|
|
Info: *log.New(os.Stdout, "[INFO] ", log.Ldate|log.Ltime),
|
|
Error: *log.New(os.Stderr, "[ERROR] ", log.Ldate|log.Ltime),
|
|
}
|
|
}
|
|
|
|
func Info(message string, args ...any) {
|
|
if len(args) == 0 {
|
|
Log.Info.Print(message)
|
|
} else {
|
|
Log.Info.Printf(message, args...)
|
|
}
|
|
}
|
|
|
|
func Error(message string, args ...any) {
|
|
if len(args) == 0 {
|
|
Log.Error.Print(message)
|
|
} else {
|
|
Log.Error.Printf(message, args...)
|
|
}
|
|
}
|