Commit 87e6a8c5 authored by Zhu Yong's avatar Zhu Yong
Browse files

Add utility function to set kinetic libary log level and log output

parent f9f8a60c
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -8,10 +8,10 @@ For details about kinetic protocol, please refer to https://github.com/Kinetic/k
package kinetic

import (
	"os"

	"github.com/Sirupsen/logrus"
	kproto "github.com/yongzhy/kinetic-go/proto"
	"io"
	"os"
)

// Create logger for Kinetic package
@@ -21,6 +21,35 @@ func init() {
	klog.Out = os.Stdout
}

type LogLevel logrus.Level

const (
	LogLevelPanic LogLevel = LogLevel(logrus.PanicLevel)
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	LogLevelFatal LogLevel = LogLevel(logrus.FatalLevel)
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	LogLevelError LogLevel = LogLevel(logrus.ErrorLevel)
	// WarnLevel level. Non-critical entries that deserve eyes.
	LogLevelWarn LogLevel = LogLevel(logrus.WarnLevel)
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	LogLevelInfo LogLevel = LogLevel(logrus.InfoLevel)
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	LogLevelDebug LogLevel = LogLevel(logrus.DebugLevel)
)

// Set kinetic libary log level
func SetLogLevel(l LogLevel) {
	klog.Level = logrus.Level(l)
}

// Set kinetic libary log output
func SetLogOutput(out io.Writer) {
	klog.Out = out
}

// ClientOptions
type ClientOptions struct {
	Host string
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import (
)

func TestUploadAppletFile(t *testing.T) {
	// file not exist, expected to fail
	file := "not/exist/applet/javapplet.jar"
	keys, err := UploadAppletFile(blockConn, file, "test-applet")
	if err != nil || len(keys) <= 0 {
@@ -13,7 +14,7 @@ func TestUploadAppletFile(t *testing.T) {
}

func TestUpdateFirmware(t *testing.T) {
	//file := "K:\\srv\\tftp\\AD-installer-v44.01.03.slod"
	// file not exist, expected to fail
	file := "not/exist/firmare/unknown-version.slod"
	err := UpdateFirmware(blockConn, file)
	if err != nil {