-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log internal errors only if HUMANLOG_LOG_LEVEL appropriately set
- Loading branch information
Showing
2 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
type loglevel int | ||
|
||
const ( | ||
debuglvl loglevel = iota | ||
infolvl | ||
warnlvl | ||
errorlvl | ||
) | ||
|
||
var logLevel = func() loglevel { | ||
switch os.Getenv("HUMANLOG_LOG_LEVEL") { | ||
case "debug": | ||
return debuglvl | ||
case "info": | ||
return infolvl | ||
case "warn": | ||
return warnlvl | ||
case "error": | ||
return errorlvl | ||
default: | ||
return errorlvl | ||
} | ||
}() | ||
|
||
func logdebug(format string, args ...interface{}) { | ||
if logLevel <= debuglvl { | ||
log.Printf("[debug] "+format, args...) | ||
} | ||
} | ||
|
||
func loginfo(format string, args ...interface{}) { | ||
if logLevel <= infolvl { | ||
log.Printf("[info] "+format, args...) | ||
} | ||
} | ||
|
||
func logwarn(format string, args ...interface{}) { | ||
if logLevel <= warnlvl { | ||
log.Printf("[warn] "+format, args...) | ||
} | ||
} | ||
|
||
func logerror(format string, args ...interface{}) { | ||
if logLevel <= errorlvl { | ||
log.Printf("[error] "+format, args...) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters