logmania/log/level.go

157 lines
3.0 KiB
Go
Raw Normal View History

2017-06-11 03:34:11 +02:00
package log
2017-06-11 01:33:35 +02:00
2017-06-13 00:21:19 +02:00
// definition of loglevel
2017-06-11 03:34:11 +02:00
type LogLevel int32
2017-06-11 01:33:35 +02:00
2017-06-13 00:21:19 +02:00
// accepted LogLevels and his internal int values
2017-06-11 01:33:35 +02:00
const (
2017-06-11 03:34:11 +02:00
DebugLevel = LogLevel(-1)
InfoLevel = LogLevel(0)
WarnLevel = LogLevel(1)
ErrorLevel = LogLevel(2)
PanicLevel = LogLevel(3)
2017-06-11 01:33:35 +02:00
)
2017-06-13 00:21:19 +02:00
// string of loglevel
2017-06-11 03:34:11 +02:00
func (l LogLevel) String() string {
2017-06-11 01:33:35 +02:00
switch l {
case DebugLevel:
return "Debug"
case InfoLevel:
return "Info"
case WarnLevel:
return "Warn"
case ErrorLevel:
return "ERROR"
case PanicLevel:
return "PANIC"
}
return "NOT VALID"
}
func NewLoglevel(by string) LogLevel {
switch by {
case "debug":
return DebugLevel
case "info":
return InfoLevel
case "warn":
return WarnLevel
case "error":
return ErrorLevel
case "panic":
return PanicLevel
}
return DebugLevel
}
2017-06-11 01:33:35 +02:00
/**
* log command
*/
2017-06-13 00:21:19 +02:00
// close logentry with debug
2017-06-11 01:33:35 +02:00
func (e *Entry) Debug(v ...interface{}) {
e.Log(DebugLevel, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with formated debug
2017-06-11 01:33:35 +02:00
func (e *Entry) Debugf(format string, v ...interface{}) {
e.Logf(DebugLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with info
2017-06-11 01:33:35 +02:00
func (e *Entry) Info(v ...interface{}) {
e.Log(InfoLevel, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with formated info
2017-06-11 01:33:35 +02:00
func (e *Entry) Infof(format string, v ...interface{}) {
e.Logf(InfoLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with warning
2017-06-11 01:33:35 +02:00
func (e *Entry) Warn(v ...interface{}) {
e.Log(WarnLevel, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with formated warning
2017-06-11 01:33:35 +02:00
func (e *Entry) Warnf(format string, v ...interface{}) {
e.Logf(WarnLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with error
2017-06-11 01:33:35 +02:00
func (e *Entry) Error(v ...interface{}) {
e.Log(ErrorLevel, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with formated error
2017-06-11 01:33:35 +02:00
func (e *Entry) Errorf(format string, v ...interface{}) {
e.Logf(ErrorLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with panic
2017-06-11 01:33:35 +02:00
func (e *Entry) Panic(v ...interface{}) {
e.Log(PanicLevel, v...)
}
2017-06-13 00:21:19 +02:00
// close logentry with formated panic
2017-06-11 01:33:35 +02:00
func (e *Entry) Panicf(format string, v ...interface{}) {
e.Logf(PanicLevel, format, v...)
}
/**
* Direct log command
*/
2017-06-13 00:21:19 +02:00
// direct log with debug
2017-06-11 01:33:35 +02:00
func Debug(v ...interface{}) {
New().Log(DebugLevel, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with formated debug
2017-06-11 01:33:35 +02:00
func Debugf(format string, v ...interface{}) {
New().Logf(DebugLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with info
2017-06-11 01:33:35 +02:00
func Info(v ...interface{}) {
New().Log(InfoLevel, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with formated info
2017-06-11 01:33:35 +02:00
func Infof(format string, v ...interface{}) {
New().Logf(InfoLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with warning
2017-06-11 01:33:35 +02:00
func Warn(v ...interface{}) {
New().Log(WarnLevel, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with formated warning
2017-06-11 01:33:35 +02:00
func Warnf(format string, v ...interface{}) {
New().Logf(WarnLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with error
2017-06-11 01:33:35 +02:00
func Error(v ...interface{}) {
New().Log(ErrorLevel, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with formated error
2017-06-11 01:33:35 +02:00
func Errorf(format string, v ...interface{}) {
New().Logf(ErrorLevel, format, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with panic
2017-06-11 01:33:35 +02:00
func Panic(v ...interface{}) {
New().Log(PanicLevel, v...)
}
2017-06-13 00:21:19 +02:00
// direct log with formated panic
2017-06-11 01:33:35 +02:00
func Panicf(format string, v ...interface{}) {
New().Logf(PanicLevel, format, v...)
}