Skip to content

Commit

Permalink
🎉 prefix at all levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Prasanna authored and Prasanna committed Jul 31, 2021
1 parent 46a0b01 commit 74e26a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (l *Logger) getLogStr(level Level, args ...interface{}) string {
str := fmt.Sprintf("%v", args...)
write := ""
println("found prefix ", l.LogPrefix)
if l.LogPrefix != "" {
if l.LogPrefix == "" {
write = fmt.Sprintf("[%s] %s %s \n", now, level, str)
} else {
write = fmt.Sprintf("[%s] [%s] %s %s \n", now, l.LogPrefix, level, str)
Expand Down
24 changes: 10 additions & 14 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"reflect"
"testing"
"time"

"github.com/signalify-in/glog"
"github.com/stretchr/testify/assert"
Expand All @@ -22,30 +23,25 @@ func TestLogger_New(t *testing.T) {
assert.Equal(t, reflect.TypeOf(logger), reflect.TypeOf(&glog.Logger{}))
}

func TestLogger_NewWithLevels(t *testing.T) {
logger.LogPrefix = "Test"
logger = glog.New(glog.LevelInfo)
assert.Equal(t, 5, len(logger.DirLevels))

logger = glog.New(glog.LevelFatal)
assert.Equal(t, 2, len(logger.DirLevels))

logger = glog.New(glog.LevelDebug)
assert.Equal(t, 6, len(logger.DirLevels))
}

func TestLogger_NewBot(t *testing.T) {}

func TestLogger_Trace(t *testing.T) {
readOutput()
logger.Trace("trace")
logger.Info(fmt.Sprintf("tracing log %v \n", len(logger.DirLevels)))
logger = glog.New(glog.LevelTrace, "Test")
assert.Equal(t, 7, len(logger.DirLevels))

logger.Trace(fmt.Sprintf("trace %v", time.Now()))
t.Log(buf.String())
}

func TestLogger_Debug(t *testing.T) {
readOutput()
logger = glog.New(glog.LevelDebug)
assert.Equal(t, 6, len(logger.DirLevels))
logger.Debug("debug")
logger = glog.New(glog.LevelDebug, "Test Debug")
logger.Debug("debug test with prefix")
//add more assertions here
t.Log(buf.String())
}

Expand Down

0 comments on commit 74e26a1

Please sign in to comment.