mirror of
https://github.com/Fishwaldo/go-logadapter.git
synced 2025-03-15 19:31:25 +00:00
parent
dcaa74a6f2
commit
bcd5299814
8 changed files with 549 additions and 235 deletions
|
@ -53,8 +53,24 @@ type Logger interface {
|
|||
SetPrefix(name string)
|
||||
// Get the Log Prefix
|
||||
GetPrefix() (string)
|
||||
// Set Logging Level
|
||||
SetLevel(Log_Level)
|
||||
// Get Logging Level
|
||||
GetLevel() (Log_Level)
|
||||
// Sync/Flush the Log Buffers
|
||||
Sync()
|
||||
}
|
||||
|
||||
|
||||
type Log_Level int
|
||||
|
||||
const (
|
||||
LOG_TRACE Log_Level = iota
|
||||
LOG_DEBUG
|
||||
LOG_INFO
|
||||
LOG_WARN
|
||||
LOG_ERROR
|
||||
LOG_FATAL
|
||||
LOG_PANIC
|
||||
LOG_UNKNOWN
|
||||
)
|
||||
|
|
|
@ -35,7 +35,7 @@ type TestStruct struct {
|
|||
|
||||
func (t *TestStruct) Init() {
|
||||
temp := stdlogger.DefaultLogger()
|
||||
temp.SetLevel(stdlogger.LOG_TRACE)
|
||||
temp.SetLevel(logadapter.LOG_TRACE)
|
||||
t.Logger = temp
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ func (l *LruLogger) Sync() {
|
|||
}
|
||||
func (l *LruLogger) New(name string) logadapter.Logger {
|
||||
nl := &LruLogger{Lru: logrus.NewEntry(l.Lru.Logger)}
|
||||
nl.SetPrefix(name)
|
||||
return nl
|
||||
}
|
||||
func (l *LruLogger) SetPrefix(name string) {
|
||||
|
@ -80,9 +81,48 @@ func (l *LruLogger) GetPrefix() (string) {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
func (l *LruLogger) SetLevel(level logadapter.Log_Level) {
|
||||
switch level {
|
||||
case logadapter.LOG_TRACE:
|
||||
l.Lru.Logger.SetLevel(logrus.TraceLevel)
|
||||
case logadapter.LOG_DEBUG:
|
||||
l.Lru.Logger.SetLevel(logrus.DebugLevel)
|
||||
case logadapter.LOG_INFO:
|
||||
l.Lru.Logger.SetLevel(logrus.InfoLevel)
|
||||
case logadapter.LOG_WARN:
|
||||
l.Lru.Logger.SetLevel(logrus.WarnLevel)
|
||||
case logadapter.LOG_ERROR:
|
||||
l.Lru.Logger.SetLevel(logrus.ErrorLevel)
|
||||
case logadapter.LOG_FATAL:
|
||||
l.Lru.Logger.SetLevel(logrus.FatalLevel)
|
||||
case logadapter.LOG_PANIC:
|
||||
l.Lru.Logger.SetLevel(logrus.PanicLevel)
|
||||
}
|
||||
}
|
||||
func (l *LruLogger) GetLevel() (logadapter.Log_Level) {
|
||||
switch l.Lru.Logger.GetLevel() {
|
||||
case logrus.TraceLevel:
|
||||
return logadapter.LOG_TRACE
|
||||
case logrus.DebugLevel:
|
||||
return logadapter.LOG_DEBUG
|
||||
case logrus.InfoLevel:
|
||||
return logadapter.LOG_INFO
|
||||
case logrus.WarnLevel:
|
||||
return logadapter.LOG_WARN
|
||||
case logrus.ErrorLevel:
|
||||
return logadapter.LOG_ERROR
|
||||
case logrus.FatalLevel:
|
||||
return logadapter.LOG_FATAL
|
||||
case logrus.PanicLevel:
|
||||
return logadapter.LOG_PANIC
|
||||
}
|
||||
return logadapter.LOG_UNKNOWN
|
||||
}
|
||||
|
||||
//LogrusDefaultLogger Return Logger based on logrus with new instance
|
||||
func LogrusDefaultLogger() logadapter.Logger {
|
||||
func LogrusDefaultLogger() (*LruLogger) {
|
||||
// TODO control verbosity
|
||||
l := &LruLogger{Lru: logrus.NewEntry(logrus.New())}
|
||||
return l
|
||||
}
|
||||
|
||||
|
|
|
@ -25,114 +25,197 @@ SOFTWARE.
|
|||
package logrus_test
|
||||
|
||||
import (
|
||||
// "bytes"
|
||||
// "os"
|
||||
// "regexp"
|
||||
"bytes"
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
// "github.com/Fishwaldo/go-logadapter/loggers/zap"
|
||||
"github.com/Fishwaldo/go-logadapter"
|
||||
"github.com/Fishwaldo/go-logadapter/loggers/logrus"
|
||||
)
|
||||
|
||||
func TestDefaultLogger(t *testing.T) {
|
||||
//_ := zaplog.ZapLogger{}
|
||||
//logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
//if logger.GetLevel() != stdlogger.LOG_TRACE {
|
||||
// t.Errorf("Can't Set Logging Level")
|
||||
//}
|
||||
func TestLogRusRusLogger(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Can't Set Logging Level")
|
||||
}
|
||||
}
|
||||
|
||||
// func captureOutput(l *zaplog.ZapLogger, f func()) string {
|
||||
// // var buf bytes.Buffer
|
||||
// // l.Log.SetOutput(&buf)
|
||||
// // f()
|
||||
// // l.Log.SetOutput(os.Stderr)
|
||||
// // return buf.String()
|
||||
// }
|
||||
func TestLogTrace(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Trace("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* TRACE: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Trace Failed: %s", output)
|
||||
// }
|
||||
func captureOutput(l *logrus.LruLogger, f func()) string {
|
||||
var buf bytes.Buffer
|
||||
l.Lru.Logger.SetOutput(&buf)
|
||||
f()
|
||||
l.Lru.Logger.SetOutput(os.Stderr)
|
||||
return buf.String()
|
||||
}
|
||||
func TestLogDebug(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Debug("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* DEBUG: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Debug Failed: %s", output)
|
||||
// }
|
||||
func TestLogRusTrace(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Trace("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=trace msg=\"Hello world\"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Trace Failed: %s - %s", output, validmsg)
|
||||
}
|
||||
}
|
||||
func TestLogRusDebug(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Debug("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=debug msg=\"Hello world"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Debug Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogInfo(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Info("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* INFO: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Info Failed: %s", output)
|
||||
// }
|
||||
func TestLogRusInfo(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Info("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=info msg=\"Hello world\"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Info Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogWarn(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Warn("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* WARN: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Warn Failed: %s", output)
|
||||
// }
|
||||
func TestLogRusWarn(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Warn("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=warning msg=\"Hello world\"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Warn Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogError(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Error("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* ERROR: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Error Failed: %s", output)
|
||||
// }
|
||||
func TestLogRusError(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Error("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=error msg=\"Hello world\"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Error Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogFatal(t *testing.T) {
|
||||
//logger := DefaultLogger()
|
||||
//logger.SetLevel(LOG_TRACE)
|
||||
//output := captureOutput(logger, func() {
|
||||
// logger.Fatal("Hello %s", "world")
|
||||
//})
|
||||
//validmsg := regexp.MustCompile(`^.* FATAL: Hello world \- {}`)
|
||||
//if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Fatal Failed: %s", output)
|
||||
//}
|
||||
func fakeExit(int) {
|
||||
/* do nothing */
|
||||
}
|
||||
func TestLogRusFatal(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
logger.Lru.Logger.ExitFunc = fakeExit
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Fatal("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=fatal msg=\"Hello world\"`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Fatal Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogPanic(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// defer func() {
|
||||
// if err := recover(); err == nil {
|
||||
// t.Errorf("Log Panic Recovery Failed")
|
||||
// }
|
||||
// }()
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Panic("Hello %s", "world")
|
||||
// })
|
||||
|
||||
// validmsg := regexp.MustCompile(`^.* PANIC: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Panic Failed: %s", output)
|
||||
// }
|
||||
func TestLogRusPanic(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Errorf("Log Panic Recovery Failed")
|
||||
}
|
||||
}()
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Panic("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* PANIC: Hello world \- {}`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Panic Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogRusWith(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
logger2 := logger.With("Test", "Message")
|
||||
|
||||
output := captureOutput(logger, func() {
|
||||
logger2.Info("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=info msg=\"Hello world\" Test=Message`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log With Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogRusPrefix(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetPrefix() != "" {
|
||||
t.Errorf("Empty Log Prefix Failed: %s", logger.GetPrefix())
|
||||
}
|
||||
logger.SetPrefix("TestLogRus")
|
||||
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Info("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=info msg=\"Hello world\" Prefix=TestLogRus`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Prefix Failed: %s", output)
|
||||
}
|
||||
if logger.GetPrefix() != "TestLogRus" {
|
||||
t.Errorf("Log Prefix Failed: %s", logger.GetPrefix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogRusLevel(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_DEBUG)
|
||||
if logger.GetLevel() != logadapter.LOG_DEBUG {
|
||||
t.Errorf("Log SetLevel to Debug Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_INFO)
|
||||
if logger.GetLevel() != logadapter.LOG_INFO {
|
||||
t.Errorf("Log SetLevel to Info Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_WARN)
|
||||
if logger.GetLevel() != logadapter.LOG_WARN {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_ERROR)
|
||||
if logger.GetLevel() != logadapter.LOG_ERROR {
|
||||
t.Errorf("Log SetLevel to Error Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_FATAL)
|
||||
if logger.GetLevel() != logadapter.LOG_FATAL {
|
||||
t.Errorf("Log SetLevel to Fatal Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_PANIC)
|
||||
if logger.GetLevel() != logadapter.LOG_PANIC {
|
||||
t.Errorf("Log SetLevel to Panic Failed: %d", logger.GetLevel())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogRusNewLog(t *testing.T) {
|
||||
logger := logrus.LogrusDefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
logger2 := logger.New("Blah")
|
||||
output := captureOutput(logger, func() {
|
||||
logger2.Error("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* level=error msg=\"Hello world\" Prefix=Blah`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Error Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import (
|
|||
"github.com/Fishwaldo/go-logadapter/internal/utils"
|
||||
)
|
||||
|
||||
var _ logadapter.Logger = (*StdLogger)(nil)
|
||||
|
||||
//DefaultLogger uses Golang Standard Logging Libary
|
||||
func DefaultLogger() (l *StdLogger) {
|
||||
stdlogger := log.New(os.Stderr, "log - ", log.LstdFlags)
|
||||
|
@ -47,56 +49,48 @@ type StdLogger struct {
|
|||
Log log.Logger
|
||||
keys map[string]interface{}
|
||||
mx sync.Mutex
|
||||
level Log_Level
|
||||
level logadapter.Log_Level
|
||||
}
|
||||
|
||||
type Log_Level int
|
||||
|
||||
const (
|
||||
LOG_TRACE Log_Level = iota
|
||||
LOG_DEBUG
|
||||
LOG_INFO
|
||||
LOG_WARN
|
||||
LOG_ERROR
|
||||
LOG_FATAL
|
||||
LOG_PANIC
|
||||
)
|
||||
|
||||
func (l *StdLogger) Trace(message string, params ...interface{}) {
|
||||
if l.level <= LOG_TRACE {
|
||||
if l.level <= logadapter.LOG_TRACE {
|
||||
l.Log.Printf("TRACE: %s - %s", fmt.Sprintf(message, params...), l.getKeys())
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Debug(message string, params ...interface{}) {
|
||||
if l.level <= LOG_DEBUG {
|
||||
if l.level <= logadapter.LOG_DEBUG {
|
||||
l.Log.Printf("DEBUG: %s - %s", fmt.Sprintf(message, params...), l.getKeys())
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Info(message string, params ...interface{}) {
|
||||
if l.level <= LOG_INFO {
|
||||
if l.level <= logadapter.LOG_INFO {
|
||||
l.Log.Printf("INFO: %s - %s", fmt.Sprintf(message, params...), l.getKeys())
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Warn(message string, params ...interface{}) {
|
||||
if l.level <= LOG_WARN {
|
||||
if l.level <= logadapter.LOG_WARN {
|
||||
l.Log.Printf("WARN: %s - %s", fmt.Sprintf(message, params...), l.getKeys())
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Error(message string, params ...interface{}) {
|
||||
if l.level <= LOG_ERROR {
|
||||
if l.level <= logadapter.LOG_ERROR {
|
||||
l.Log.Printf("ERROR: %s - %s", fmt.Sprintf(message, params...), l.getKeys())
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Fatal(message string, params ...interface{}) {
|
||||
if l.level <= logadapter.LOG_FATAL {
|
||||
l.Log.Fatal(fmt.Printf("FATAL: %s - %s", fmt.Sprintf(message, params...), l.getKeys()))
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) Panic(message string, params ...interface{}) {
|
||||
if l.level <= logadapter.LOG_PANIC {
|
||||
l.Log.Panic(fmt.Printf("PANIC: %s - %s", fmt.Sprintf(message, params...), l.getKeys()))
|
||||
}
|
||||
}
|
||||
func (l *StdLogger) New(name string) logadapter.Logger {
|
||||
//nl := &StdLogger{keys: l.keys}
|
||||
nl := &StdLogger{level: l.level}
|
||||
nl.Log.SetPrefix(fmt.Sprintf("%s.%s", l.Log.Prefix(), name))
|
||||
nl := &StdLogger{level: l.level, keys: make(map[string]interface{})}
|
||||
nl.SetPrefix(name)
|
||||
nl.Log.SetFlags(l.Log.Flags())
|
||||
nl.Log.SetOutput(l.Log.Writer())
|
||||
return nl
|
||||
|
@ -105,7 +99,7 @@ func (l *StdLogger) With(key string, value interface{}) logadapter.Logger {
|
|||
l.mx.Lock()
|
||||
defer l.mx.Unlock()
|
||||
stdlog := &StdLogger{level: l.level, keys: utils.CopyableMap(l.keys).DeepCopy()}
|
||||
stdlog.Log.SetPrefix(l.Log.Prefix())
|
||||
stdlog.SetPrefix(l.GetPrefix())
|
||||
stdlog.Log.SetFlags(l.Log.Flags())
|
||||
stdlog.Log.SetOutput(l.Log.Writer())
|
||||
stdlog.keys[key] = value
|
||||
|
@ -125,11 +119,11 @@ func (l *StdLogger) getKeys() (message string) {
|
|||
return err.Error()
|
||||
}
|
||||
|
||||
func (l *StdLogger) SetLevel(level Log_Level) {
|
||||
func (l *StdLogger) SetLevel(level logadapter.Log_Level) {
|
||||
l.level = level
|
||||
}
|
||||
|
||||
func (l *StdLogger) GetLevel() (level Log_Level) {
|
||||
func (l *StdLogger) GetLevel() (logadapter.Log_Level) {
|
||||
return l.level
|
||||
}
|
||||
|
||||
|
|
|
@ -30,13 +30,14 @@ import (
|
|||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/Fishwaldo/go-logadapter"
|
||||
"github.com/Fishwaldo/go-logadapter/loggers/std"
|
||||
)
|
||||
|
||||
func TestDefaultLogger(t *testing.T) {
|
||||
func TestStdLogger(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
if logger.GetLevel() != stdlogger.LOG_TRACE {
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Can't Set Logging Level")
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +49,9 @@ func captureOutput(l *stdlogger.StdLogger, f func()) string {
|
|||
l.Log.SetOutput(os.Stderr)
|
||||
return buf.String()
|
||||
}
|
||||
func TestLogTrace(t *testing.T) {
|
||||
func TestStdTrace(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Trace("Hello %s", "world")
|
||||
})
|
||||
|
@ -59,9 +60,9 @@ func TestLogTrace(t *testing.T) {
|
|||
t.Errorf("Log Trace Failed: %s", output)
|
||||
}
|
||||
}
|
||||
func TestLogDebug(t *testing.T) {
|
||||
func TestStdDebug(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Debug("Hello %s", "world")
|
||||
})
|
||||
|
@ -71,9 +72,9 @@ func TestLogDebug(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLogInfo(t *testing.T) {
|
||||
func TestStdInfo(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Info("Hello %s", "world")
|
||||
})
|
||||
|
@ -83,9 +84,9 @@ func TestLogInfo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLogWarn(t *testing.T) {
|
||||
func TestStdWarn(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Warn("Hello %s", "world")
|
||||
})
|
||||
|
@ -95,9 +96,9 @@ func TestLogWarn(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLogError(t *testing.T) {
|
||||
func TestStdError(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Error("Hello %s", "world")
|
||||
})
|
||||
|
@ -107,7 +108,7 @@ func TestLogError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLogFatal(t *testing.T) {
|
||||
func TestStdFatal(t *testing.T) {
|
||||
//logger := DefaultLogger()
|
||||
//logger.SetLevel(LOG_TRACE)
|
||||
//output := captureOutput(logger, func() {
|
||||
|
@ -119,9 +120,9 @@ func TestLogFatal(t *testing.T) {
|
|||
//}
|
||||
}
|
||||
|
||||
func TestLogPanic(t *testing.T) {
|
||||
func TestStdPanic(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Errorf("Log Panic Recovery Failed")
|
||||
|
@ -136,3 +137,81 @@ func TestLogPanic(t *testing.T) {
|
|||
t.Errorf("Log Panic Failed: %s", output)
|
||||
}
|
||||
}
|
||||
func TestStdPrefix(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetPrefix() != "log" {
|
||||
t.Errorf("Empty Log Prefix Failed: %s", logger.GetPrefix())
|
||||
}
|
||||
logger.SetPrefix("TestStd")
|
||||
|
||||
output := captureOutput(logger, func() {
|
||||
logger.Info("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^TestStd .* INFO: Hello world \- {}`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Prefix Failed: %s", output)
|
||||
}
|
||||
if logger.GetPrefix() != "TestStd" {
|
||||
t.Errorf("Log Prefix Failed: %s", logger.GetPrefix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestStdLevel(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_DEBUG)
|
||||
if logger.GetLevel() != logadapter.LOG_DEBUG {
|
||||
t.Errorf("Log SetLevel to Debug Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_INFO)
|
||||
if logger.GetLevel() != logadapter.LOG_INFO {
|
||||
t.Errorf("Log SetLevel to Info Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_WARN)
|
||||
if logger.GetLevel() != logadapter.LOG_WARN {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_ERROR)
|
||||
if logger.GetLevel() != logadapter.LOG_ERROR {
|
||||
t.Errorf("Log SetLevel to Error Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_FATAL)
|
||||
if logger.GetLevel() != logadapter.LOG_FATAL {
|
||||
t.Errorf("Log SetLevel to Fatal Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_PANIC)
|
||||
if logger.GetLevel() != logadapter.LOG_PANIC {
|
||||
t.Errorf("Log SetLevel to Panic Failed: %d", logger.GetLevel())
|
||||
}
|
||||
}
|
||||
|
||||
func TestStdNewLog(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
logger2 := logger.New("Blah")
|
||||
output := captureOutput(logger2.(*stdlogger.StdLogger), func() {
|
||||
logger2.Error("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^Blah .* ERROR: Hello world \- {}`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log Error Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStdWith(t *testing.T) {
|
||||
logger := stdlogger.DefaultLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
logger2 := logger.With("Test", "Message")
|
||||
|
||||
output := captureOutput(logger2.(*stdlogger.StdLogger), func() {
|
||||
logger2.Info("Hello %s", "world")
|
||||
})
|
||||
validmsg := regexp.MustCompile(`^.* INFO: Hello world \- {\"Test\":\"Message\"}`)
|
||||
if !validmsg.MatchString(output) {
|
||||
t.Errorf("Log With Failed: %s", output)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ var _ logadapter.Logger = (*ZapLogger)(nil)
|
|||
|
||||
type ZapLogger struct {
|
||||
Zap *zap.SugaredLogger
|
||||
lvl logadapter.Log_Level
|
||||
}
|
||||
|
||||
func (l *ZapLogger) With(key string, value interface{}) logadapter.Logger {
|
||||
|
@ -41,25 +42,39 @@ func (l *ZapLogger) With(key string, value interface{}) logadapter.Logger {
|
|||
}
|
||||
|
||||
func (l *ZapLogger) Trace(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_TRACE {
|
||||
l.Zap.Debugf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Debug(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_DEBUG {
|
||||
l.Zap.Debugf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Info(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_INFO {
|
||||
l.Zap.Infof(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Warn(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_WARN {
|
||||
l.Zap.Warnf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Error(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_ERROR {
|
||||
l.Zap.Errorf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Fatal(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_FATAL {
|
||||
l.Zap.Fatalf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) Panic(message string, params ...interface{}) {
|
||||
if l.lvl <= logadapter.LOG_PANIC {
|
||||
l.Zap.Panicf(message, params...)
|
||||
}
|
||||
}
|
||||
func (l *ZapLogger) New(name string) (nl logadapter.Logger) {
|
||||
zl := &ZapLogger{Zap: l.Zap}
|
||||
|
@ -78,6 +93,13 @@ func (l ZapLogger) GetPrefix() (string) {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (l *ZapLogger) GetLevel() (logadapter.Log_Level) {
|
||||
return l.lvl
|
||||
}
|
||||
func (l *ZapLogger) SetLevel(lvl logadapter.Log_Level) {
|
||||
l.lvl = lvl
|
||||
}
|
||||
|
||||
//DefaultLogger Return Default Sched Logger based on Zap's sugared logger
|
||||
func NewZapLogger() *ZapLogger {
|
||||
// TODO control verbosity
|
||||
|
|
|
@ -30,109 +30,189 @@ import (
|
|||
// "regexp"
|
||||
"testing"
|
||||
|
||||
// "github.com/Fishwaldo/go-logadapter/loggers/zap"
|
||||
"github.com/Fishwaldo/go-logadapter"
|
||||
"github.com/Fishwaldo/go-logadapter/loggers/zap"
|
||||
)
|
||||
|
||||
func TestDefaultLogger(t *testing.T) {
|
||||
//_ := zaplog.ZapLogger{}
|
||||
//logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
//if logger.GetLevel() != stdlogger.LOG_TRACE {
|
||||
// t.Errorf("Can't Set Logging Level")
|
||||
//}
|
||||
func TestZapLogger(t *testing.T) {
|
||||
logger := zaplog.NewZapLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Can't Set Logging Level")
|
||||
}
|
||||
}
|
||||
|
||||
// func captureOutput(l *zaplog.ZapLogger, f func()) string {
|
||||
// // var buf bytes.Buffer
|
||||
// // l.Log.SetOutput(&buf)
|
||||
// // f()
|
||||
// // l.Log.SetOutput(os.Stderr)
|
||||
// // return buf.String()
|
||||
// var buf bytes.Buffer
|
||||
// l.Log.SetOutput(&buf)
|
||||
// f()
|
||||
// l.Log.SetOutput(os.Stderr)
|
||||
// return buf.String()
|
||||
// }
|
||||
func TestLogTrace(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Trace("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* TRACE: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Trace Failed: %s", output)
|
||||
// }
|
||||
}
|
||||
func TestLogDebug(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Debug("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* DEBUG: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Debug Failed: %s", output)
|
||||
// }
|
||||
// func TestLogTrace(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Trace("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* TRACE: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Trace Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
// func TestLogDebug(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Debug("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* DEBUG: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Debug Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestLogInfo(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Info("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* INFO: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Info Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestLogWarn(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Warn("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* WARN: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Warn Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestLogError(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Error("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* ERROR: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Error Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestLogFatal(t *testing.T) {
|
||||
// logger := DefaultLogger()
|
||||
// logger.SetLevel(LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Fatal("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* FATAL: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Fatal Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestLogPanic(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// defer func() {
|
||||
// if err := recover(); err == nil {
|
||||
// t.Errorf("Log Panic Recovery Failed")
|
||||
// }
|
||||
// }()
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Panic("Hello %s", "world")
|
||||
// })
|
||||
|
||||
// validmsg := regexp.MustCompile(`^.* PANIC: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Panic Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
// func TestLogPrefix(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// if logger.GetPrefix() != "log" {
|
||||
// t.Errorf("Empty Log Prefix Failed: %s", logger.GetPrefix())
|
||||
// }
|
||||
// logger.SetPrefix("TestLog")
|
||||
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Info("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^TestLog .* INFO: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Prefix Failed: %s", output)
|
||||
// }
|
||||
// if logger.GetPrefix() != "TestLog" {
|
||||
// t.Errorf("Log Prefix Failed: %s", logger.GetPrefix())
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestZapLevel(t *testing.T) {
|
||||
logger := zaplog.NewZapLogger()
|
||||
logger.SetLevel(logadapter.LOG_TRACE)
|
||||
if logger.GetLevel() != logadapter.LOG_TRACE {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_DEBUG)
|
||||
if logger.GetLevel() != logadapter.LOG_DEBUG {
|
||||
t.Errorf("Log SetLevel to Debug Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_INFO)
|
||||
if logger.GetLevel() != logadapter.LOG_INFO {
|
||||
t.Errorf("Log SetLevel to Info Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_WARN)
|
||||
if logger.GetLevel() != logadapter.LOG_WARN {
|
||||
t.Errorf("Log SetLevel to Trace Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_ERROR)
|
||||
if logger.GetLevel() != logadapter.LOG_ERROR {
|
||||
t.Errorf("Log SetLevel to Error Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_FATAL)
|
||||
if logger.GetLevel() != logadapter.LOG_FATAL {
|
||||
t.Errorf("Log SetLevel to Fatal Failed: %d", logger.GetLevel())
|
||||
}
|
||||
logger.SetLevel(logadapter.LOG_PANIC)
|
||||
if logger.GetLevel() != logadapter.LOG_PANIC {
|
||||
t.Errorf("Log SetLevel to Panic Failed: %d", logger.GetLevel())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogInfo(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Info("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* INFO: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Info Failed: %s", output)
|
||||
// }
|
||||
}
|
||||
// func TestNewLog(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// logger2 := logger.New("Blah")
|
||||
// output := captureOutput(logger2.(*stdlogger.StdLogger), func() {
|
||||
// logger2.Error("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^Blah .* ERROR: Hello world \- {}`)
|
||||
// t.Logf("%+v", logger2)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Error Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestLogWarn(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Warn("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* WARN: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Warn Failed: %s", output)
|
||||
// }
|
||||
}
|
||||
// func TestLogWith(t *testing.T) {
|
||||
// logger := zaplog.NewZapLogger()
|
||||
// logger.SetLevel(logadapter.LOG_TRACE)
|
||||
// logger2 := logger.With("Test", "Message")
|
||||
|
||||
func TestLogError(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Error("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* ERROR: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Error Failed: %s", output)
|
||||
// }
|
||||
}
|
||||
|
||||
func TestLogFatal(t *testing.T) {
|
||||
//logger := DefaultLogger()
|
||||
//logger.SetLevel(LOG_TRACE)
|
||||
//output := captureOutput(logger, func() {
|
||||
// logger.Fatal("Hello %s", "world")
|
||||
//})
|
||||
//validmsg := regexp.MustCompile(`^.* FATAL: Hello world \- {}`)
|
||||
//if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Fatal Failed: %s", output)
|
||||
//}
|
||||
}
|
||||
|
||||
func TestLogPanic(t *testing.T) {
|
||||
// logger := stdlogger.DefaultLogger()
|
||||
// logger.SetLevel(stdlogger.LOG_TRACE)
|
||||
// defer func() {
|
||||
// if err := recover(); err == nil {
|
||||
// t.Errorf("Log Panic Recovery Failed")
|
||||
// }
|
||||
// }()
|
||||
// output := captureOutput(logger, func() {
|
||||
// logger.Panic("Hello %s", "world")
|
||||
// })
|
||||
|
||||
// validmsg := regexp.MustCompile(`^.* PANIC: Hello world \- {}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log Panic Failed: %s", output)
|
||||
// }
|
||||
}
|
||||
// output := captureOutput(logger2.(*stdlogger.StdLogger), func() {
|
||||
// logger2.Info("Hello %s", "world")
|
||||
// })
|
||||
// validmsg := regexp.MustCompile(`^.* INFO: Hello world \- {\"Test\":\"Message\"}`)
|
||||
// if !validmsg.MatchString(output) {
|
||||
// t.Errorf("Log With Failed: %s", output)
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Add table
Reference in a new issue