Skip to content

Commit

Permalink
Log: adds SugarLogger to Badger
Browse files Browse the repository at this point in the history
  • Loading branch information
azak-azkaran committed Nov 6, 2020
1 parent 4c1c93f commit 4193b6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
20 changes: 0 additions & 20 deletions job_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"testing"
"time"
Expand Down Expand Up @@ -72,21 +70,3 @@ func TestJobRunJob(t *testing.T) {
assert.Equal(t, "TEST=hallo\n", j.Stdout.String())
assert.Equal(t, "", j.Stderr.String())
}

func TestJobQueueStatus(t *testing.T) {
fmt.Println("running: TestJobQueueStatus")
t.Cleanup(clear)

cmd := exec.Command("echo", "hallo")

job := CreateJobFromCommand(cmd, "test1")
var infoBuffer bytes.Buffer

GetLogger().SetOutput(&infoBuffer)
job.QueueStatus()

assert.NotEmpty(t, infoBuffer)

GetLogger().SetOutput(os.Stdout)
Sugar.Info("test: ", infoBuffer.String())
}
5 changes: 4 additions & 1 deletion restrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,10 @@ func RunRestServer(address string) (*http.Server, func()) {
}

func CreateRestHandler() http.Handler {
r := gin.Default()
r := gin.New()
r.Use(gin.LoggerWithConfig(*logconfig))
r.Use(gin.Recovery())

r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
REST_JSON_MESSAGE: "pong",
Expand Down
22 changes: 20 additions & 2 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,32 @@ import (

var closed = true

type defaultLog struct{}

func (l *defaultLog) Errorf(f string, v ...interface{}) {
Sugar.Errorf(f, v...)
}

func (l *defaultLog) Infof(f string, v ...interface{}) {
Sugar.Infof(f, v...)
}

func (l *defaultLog) Debugf(f string, v ...interface{}) {
Sugar.Debugf(f, v...)
}
func (l *defaultLog) Warningf(f string, v ...interface{}) {
Sugar.Warnf(f, v...)
}

func InitDB(path string, masterkey string, debug bool) *badger.DB {
var opt badger.Options

if debug {
Sugar.Warn("Debug is on switching to InMemory")

opt = badger.DefaultOptions("").WithInMemory(true)
opt = badger.DefaultOptions("").WithInMemory(true).WithLogger(&defaultLog{})
} else {
opt = badger.DefaultOptions(path)
opt = badger.DefaultOptions(path).WithLogger(&defaultLog{})
}

if masterkey != "" {
Expand Down

0 comments on commit 4193b6e

Please sign in to comment.