mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Make log level configurable
This commit is contained in:
@@ -2,6 +2,7 @@ package log
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LogLevel int
|
||||
@@ -15,6 +16,24 @@ const (
|
||||
|
||||
var MaxLogLevel LogLevel = TRACE
|
||||
|
||||
// SetLogLevel sets MaxLogLevel based on the provided string
|
||||
func SetLogLevel(level string) (ok bool) {
|
||||
switch strings.ToUpper(level) {
|
||||
case "ERROR":
|
||||
MaxLogLevel = ERROR
|
||||
case "WARN":
|
||||
MaxLogLevel = WARN
|
||||
case "INFO":
|
||||
MaxLogLevel = INFO
|
||||
case "TRACE":
|
||||
MaxLogLevel = TRACE
|
||||
default:
|
||||
Error("Unknown log level requested: %v", level)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Error logs a message to the 'standard' Logger (always)
|
||||
func Error(msg string, args ...interface{}) {
|
||||
msg = "[ERROR] " + msg
|
||||
|
||||
Reference in New Issue
Block a user