2019-06-15 21:14:09 -05:00
|
|
|
package log
|
|
|
|
|
|
|
|
/*
|
2019-06-16 09:08:38 -05:00
|
|
|
override the log
|
2019-06-15 21:14:09 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
import "fmt"
|
2019-06-16 09:08:38 -05:00
|
|
|
import "strings"
|
2019-06-15 21:14:09 -05:00
|
|
|
import origlog "log"
|
|
|
|
import "github.com/sirupsen/logrus"
|
2019-06-16 09:08:38 -05:00
|
|
|
|
|
|
|
var newlog = logrus.New()
|
|
|
|
var systemdlog *logrus.Logger
|
2019-06-15 21:14:09 -05:00
|
|
|
|
|
|
|
var debug bool = false
|
|
|
|
var warn bool = false
|
|
|
|
var err bool = false
|
|
|
|
|
2019-06-16 09:08:38 -05:00
|
|
|
type Log struct {
|
|
|
|
Debug bool
|
|
|
|
Warn bool
|
|
|
|
Err bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *Log {
|
|
|
|
var tmp Log
|
|
|
|
return &tmp
|
|
|
|
}
|
|
|
|
|
2019-06-15 21:14:09 -05:00
|
|
|
func SetDebug(a bool) {
|
|
|
|
debug = a
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetWarn(a bool) {
|
|
|
|
warn = a
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetError(a bool) {
|
|
|
|
err = a
|
|
|
|
}
|
|
|
|
|
2019-06-16 09:08:38 -05:00
|
|
|
func (a *Log) Printer(b string) {
|
|
|
|
origlog.Println(b)
|
|
|
|
}
|
|
|
|
|
2019-06-15 21:14:09 -05:00
|
|
|
func Print(a ...interface{}) {
|
|
|
|
origlog.Println(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Println(format string, a ...interface{}) {
|
2019-06-16 09:08:38 -05:00
|
|
|
// if (debug) {
|
|
|
|
// newlog.Println(a)
|
|
|
|
// }
|
2019-06-15 21:14:09 -05:00
|
|
|
var tmp string
|
|
|
|
if (a == nil) {
|
|
|
|
tmp = fmt.Sprintf(format)
|
|
|
|
} else {
|
|
|
|
tmp = fmt.Sprintf(format, a)
|
|
|
|
}
|
2019-06-16 09:08:38 -05:00
|
|
|
|
|
|
|
// log each line
|
|
|
|
lines := strings.Split(Chomp(tmp), "\n")
|
|
|
|
for _, line := range lines {
|
|
|
|
origlog.Println(line)
|
|
|
|
}
|
2019-06-15 21:14:09 -05:00
|
|
|
}
|
|
|
|
|
2019-06-16 09:08:38 -05:00
|
|
|
func Debug(format string, a ...interface{}) {
|
2019-06-15 21:14:09 -05:00
|
|
|
if (debug) {
|
2019-06-16 09:08:38 -05:00
|
|
|
newlog.Debug(format, a)
|
|
|
|
systemdlog.Println("SYSTEMLOG:", format, a)
|
2019-06-15 21:14:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Debugln(a ...interface{}) {
|
|
|
|
if (debug) {
|
2019-06-16 09:08:38 -05:00
|
|
|
newlog.Debug(a)
|
|
|
|
systemdlog.Println("SYSTEMLOG:", a)
|
2019-06-15 21:14:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Warn(a ...interface{}) {
|
|
|
|
origlog.Println(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Error(a ...interface{}) {
|
|
|
|
origlog.Println(a)
|
|
|
|
}
|