You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
873 B
44 lines
873 B
package log
|
|
|
|
import (
|
|
internalLog "log"
|
|
"sync"
|
|
)
|
|
|
|
// Global variable to be set
|
|
var verbosity = NormalLOG
|
|
var mutex sync.RWMutex
|
|
|
|
func verify(level Level) bool {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return Level(verbosity) >= level
|
|
}
|
|
|
|
// SetVerbosity - set log level value globally
|
|
func SetVerbosity(level Level) {
|
|
mutex.Lock()
|
|
defer mutex.Unlock()
|
|
verbosity = level
|
|
}
|
|
|
|
// Log - variable logging against global verbosity
|
|
func Log(level Level, args ...interface{}) {
|
|
if verify(level) {
|
|
internalLog.Print(args...)
|
|
}
|
|
}
|
|
|
|
// Logf - variable formatted logging against global verbosity
|
|
func Logf(level Level, s string, args ...interface{}) {
|
|
if verify(level) {
|
|
internalLog.Printf(s, args...)
|
|
}
|
|
}
|
|
|
|
// Logln - variable logging with newline against global verbosity
|
|
func Logln(level Level, args ...interface{}) {
|
|
if verify(level) {
|
|
internalLog.Println(args...)
|
|
}
|
|
}
|
|
|