1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

Make log level configurable

This commit is contained in:
James Hillyerd
2012-10-22 18:07:16 -07:00
parent 3099777044
commit 16a68000d3
5 changed files with 101 additions and 0 deletions

View File

@@ -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