1
0
Fork 0
mirror of https://github.com/Luzifer/s3sync.git synced 2024-10-18 14:34:20 +00:00
s3sync/logger/logger.go

56 lines
1.2 KiB
Go
Raw Permalink Normal View History

package logger
import "fmt"
2015-07-28 14:09:42 +00:00
// LogLevel defines a type for named log levels
type LogLevel uint
2015-07-28 14:09:42 +00:00
// Pre-Defined log levels to be used with this logging module
const (
Error LogLevel = iota
Warning
Info
Debug
)
// Logger is a wrapper around output to filter according to levels
type Logger struct {
Level LogLevel
}
2015-07-28 14:09:42 +00:00
// New instanciates a new Logger and sets the preferred log level
func New(logLevel LogLevel) *Logger {
return &Logger{
Level: logLevel,
}
}
2015-07-28 14:09:42 +00:00
// Log is the filtered equivalent to fmt.Println
func (l *Logger) Log(level LogLevel, line string) {
if l.Level >= level {
fmt.Println(line)
}
}
2015-07-28 14:09:42 +00:00
// LogF is the filtered equivalent to fmt.Printf
func (l *Logger) LogF(level LogLevel, line string, args ...interface{}) {
if l.Level >= level {
fmt.Printf(line, args...)
}
}
2015-07-28 14:09:42 +00:00
// ErrorF executes LogF with Error level
func (l *Logger) ErrorF(line string, args ...interface{}) {
l.LogF(Error, line, args...)
}
2015-07-28 14:09:42 +00:00
// InfoF executes LogF with Info level
func (l *Logger) InfoF(line string, args ...interface{}) {
l.LogF(Info, line, args...)
}
2015-07-28 14:09:42 +00:00
// DebugF executes LogF with Debug level
func (l *Logger) DebugF(line string, args ...interface{}) {
l.LogF(Debug, line, args...)
}