VMware vSphere Integrated Containers provider (#206)

* Add Virtual Kubelet provider for VIC

Initial virtual kubelet provider for VMware VIC.  This provider currently
handles creating and starting of a pod VM via the VIC portlayer and persona
server.  Image store handling via the VIC persona server.  This provider
currently requires the feature/wolfpack branch of VIC.

* Added pod stop and delete.  Also added node capacity.

Added the ability to stop and delete pod VMs via VIC.  Also retrieve
node capacity information from the VCH.

* Cleanup and readme file

Some file clean up and added a Readme.md markdown file for the VIC
provider.

* Cleaned up errors, added function comments, moved operation code

1. Cleaned up error handling.  Set standard for creating errors.
2. Added method prototype comments for all interface functions.
3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder.

* Add mocking code and unit tests for podcache, podcreator, and podstarter

Used the unit test framework used in VIC to handle assertions in the provider's
unit test.  Mocking code generated using OSS project mockery, which is compatible
with the testify assertion framework.

* Vendored packages for the VIC provider

Requires feature/wolfpack branch of VIC and a few specific commit sha of
projects used within VIC.

* Implementation of POD Stopper and Deleter unit tests (#4)

* Updated files for initial PR
This commit is contained in:
Loc Nguyen
2018-06-04 15:41:32 -07:00
committed by Ria Bhatia
parent 98a111e8b7
commit 513cebe7b7
6296 changed files with 1123685 additions and 8 deletions

45
vendor/github.com/vmware/vic/pkg/trace/entry.go generated vendored Normal file
View File

@@ -0,0 +1,45 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trace
import (
"github.com/Sirupsen/logrus"
)
// Entry is like logrus.Entry, but for Operation. Functionality is added as needed.
type Entry struct {
// Contains all the fields set by the user.
Data logrus.Fields
// A reference to the operation-local logger the entry was constructed for.
local *logrus.Logger
}
func (o *Operation) WithFields(fields logrus.Fields) *Entry {
entry := Entry{
Data: fields,
local: o.Logger,
}
return &entry
}
func (e *Entry) Debug(args ...interface{}) {
Logger.WithFields(e.Data).Debug(args...)
if e.local != nil {
e.local.WithFields(e.Data).Debug(args...)
}
}

318
vendor/github.com/vmware/vic/pkg/trace/operation.go generated vendored Normal file
View File

@@ -0,0 +1,318 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trace
import (
"bytes"
"context"
"fmt"
"os"
"sync/atomic"
"time"
"github.com/Sirupsen/logrus"
"github.com/vmware/govmomi/vim25/types"
)
type OperationKey string
const OpTraceKey OperationKey = "traceKey"
var opIDPrefix = os.Getpid()
// opCount is a monotonic counter which increments on Start()
var opCount uint64
type Operation struct {
context.Context
operation
// Logger is used to configure an Operation-specific destination for log messages, in addition
// to the global logger. This logger is passed to any children which are created.
Logger *logrus.Logger
}
type operation struct {
t []Message
id string
}
func newOperation(ctx context.Context, id string, skip int, msg string) Operation {
op := operation{
// Can be used to trace based on this number which is unique per chain
// of operations
id: id,
// Start the trace.
t: []Message{*newTrace(msg, skip, id)},
}
// We need to be able to identify this operation across API (and process)
// boundaries. So add the trace as a value to the embedded context. We
// stash the values individually in the context because we can't assign
// the operation itself as a value to the embedded context (it's circular)
ctx = context.WithValue(ctx, OpTraceKey, op)
// By adding the op.id any operations passed to govmomi will result
// in the op.id being logged in vSphere (vpxa / hostd) as the prefix to opID
// For example if the op.id was 299.16 hostd would show
// verbose hostd[12281B70] [Originator@6876 sub=PropertyProvider opID=299.16-5b05 user=root]
ctx = context.WithValue(ctx, types.ID{}, op.id)
o := Operation{
Context: ctx,
operation: op,
}
return o
}
// Creates a header string to be printed.
func (o *Operation) header() string {
return fmt.Sprintf("op=%s", o.id)
}
// Err returns a non-nil error value after Done is closed. Err returns
// Canceled if the context was canceled or DeadlineExceeded if the
// context's deadline passed. No other values for Err are defined.
// After Done is closed, successive calls to Err return the same value.
func (o Operation) Err() error {
// Walk up the contexts from which this context was created and get their errors
if err := o.Context.Err(); err != nil {
buf := &bytes.Buffer{}
// Add a frame for this Err call, then walk the stack
currFrame := newTrace("Err", 2, o.id)
fmt.Fprintf(buf, "%s: %s error: %s\n", currFrame.funcName, o.t[0].msg, err)
// handle the carriage return
numFrames := len(o.t)
for i, t := range o.t {
fmt.Fprintf(buf, "%-15s:%d %s", t.funcName, t.lineNo, t.msg)
// don't add a cr on the last frame
if i != numFrames-1 {
buf.WriteByte('\n')
}
}
// Print the error
o.Errorf(buf.String())
return err
}
return nil
}
func (o Operation) String() string {
return o.header()
}
func (o *Operation) ID() string {
return o.id
}
func (o *Operation) Infof(format string, args ...interface{}) {
o.Info(fmt.Sprintf(format, args...))
}
func (o *Operation) Info(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Infof("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Info(msg)
}
}
func (o *Operation) Debugf(format string, args ...interface{}) {
o.Debug(fmt.Sprintf(format, args...))
}
func (o *Operation) Debug(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Debugf("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Debug(msg)
}
}
func (o *Operation) Warnf(format string, args ...interface{}) {
o.Warn(fmt.Sprintf(format, args...))
}
func (o *Operation) Warn(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Warnf("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Warn(msg)
}
}
func (o *Operation) Errorf(format string, args ...interface{}) {
o.Error(fmt.Sprintf(format, args...))
}
func (o *Operation) Error(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Errorf("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Error(msg)
}
}
func (o *Operation) Panicf(format string, args ...interface{}) {
o.Panic(fmt.Sprintf(format, args...))
}
func (o *Operation) Panic(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Panicf("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Panic(msg)
}
}
func (o *Operation) Fatalf(format string, args ...interface{}) {
o.Fatal(fmt.Sprintf(format, args...))
}
func (o *Operation) Fatal(args ...interface{}) {
msg := fmt.Sprint(args...)
Logger.Fatalf("%s: %s", o.header(), msg)
if o.Logger != nil {
o.Logger.Fatal(msg)
}
}
func (o *Operation) newChild(ctx context.Context, msg string) Operation {
child := newOperation(ctx, o.id, 4, msg)
child.t = append(child.t, o.t...)
child.Logger = o.Logger
return child
}
func opID(opNum uint64) string {
return fmt.Sprintf("%d.%d", opIDPrefix, opNum)
}
// NewOperation will return a new operation with operationID added as a value to the context
func NewOperation(ctx context.Context, format string, args ...interface{}) Operation {
o := newOperation(ctx, opID(atomic.AddUint64(&opCount, 1)), 3, fmt.Sprintf(format, args...))
frame := o.t[0]
o.Debugf("[NewOperation] %s [%s:%d]", o.header(), frame.funcName, frame.lineNo)
return o
}
// NewOperationWithLoggerFrom will return a new operation with operationID added as a value to the
// context and logging settings copied from the supplied operation.
//
// Deprecated: This method was added to aid in converting old code to use operation-based logging.
// Its use almost always indicates a broken context/operation model (e.g., a context
// being improperly stored in a struct instead of being passed between functions).
func NewOperationWithLoggerFrom(ctx context.Context, oldOp Operation, format string, args ...interface{}) Operation {
op := NewOperation(ctx, format, args...)
op.Logger = oldOp.Logger
return op
}
// WithTimeout creates a new operation from parent with context.WithTimeout
func WithTimeout(parent *Operation, timeout time.Duration, format string, args ...interface{}) (Operation, context.CancelFunc) {
ctx, cancelFunc := context.WithTimeout(parent.Context, timeout)
op := parent.newChild(ctx, fmt.Sprintf(format, args...))
return op, cancelFunc
}
// WithDeadline creates a new operation from parent with context.WithDeadline
func WithDeadline(parent *Operation, expiration time.Time, format string, args ...interface{}) (Operation, context.CancelFunc) {
ctx, cancelFunc := context.WithDeadline(parent.Context, expiration)
op := parent.newChild(ctx, fmt.Sprintf(format, args...))
return op, cancelFunc
}
// WithCancel creates a new operation from parent with context.WithCancel
func WithCancel(parent *Operation, format string, args ...interface{}) (Operation, context.CancelFunc) {
ctx, cancelFunc := context.WithCancel(parent.Context)
op := parent.newChild(ctx, fmt.Sprintf(format, args...))
return op, cancelFunc
}
// WithValue creates a new operation from parent with context.WithValue
func WithValue(parent *Operation, key, val interface{}, format string, args ...interface{}) Operation {
ctx := context.WithValue(parent.Context, key, val)
op := parent.newChild(ctx, fmt.Sprintf(format, args...))
return op
}
// FromOperation creates a child operation from the one supplied
// uses the same context as the parent
func FromOperation(parent Operation, format string, args ...interface{}) Operation {
return parent.newChild(parent.Context, fmt.Sprintf(format, args...))
}
// FromContext will return an Operation
//
// The Operation returned will be one of the following:
// The operation in the context value
// The operation passed as the context param
// A new operation
func FromContext(ctx context.Context, message string, args ...interface{}) Operation {
// do we have an operation
if op, ok := ctx.(Operation); ok {
return op
}
// do we have a context w/the op added as a value
if op, ok := ctx.Value(OpTraceKey).(operation); ok {
// ensure we have an initialized operation
if op.id == "" {
return NewOperation(ctx, message, args...)
}
// return an operation based off the context value
return Operation{
Context: ctx,
operation: op,
}
}
op := newOperation(ctx, opID(atomic.AddUint64(&opCount, 1)), 3, fmt.Sprintf(message, args...))
frame := op.t[0]
Logger.Debugf("%s: [OperationFromContext] [%s:%d]", op.id, frame.funcName, frame.lineNo)
// return the new operation
return op
}

View File

@@ -0,0 +1,306 @@
// Copyright 2016-2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trace
import (
"bytes"
"context"
"fmt"
"strings"
"sync"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestContextUnpack(t *testing.T) {
Logger.Level = logrus.DebugLevel
cnt := 100
wg := &sync.WaitGroup{}
wg.Add(cnt)
for i := 0; i < cnt; i++ {
go func(i int) {
defer wg.Done()
ctx := NewOperation(context.TODO(), "testmsg")
// unpack an Operation via the context using it's Values fields
c := FromContext(ctx, "test")
c.Infof("test info message %d", i)
}(i) // fix race in test
}
wg.Wait()
}
// If we timeout a child, test a stack is printed of contexts
func TestNestedLogging(t *testing.T) {
// create a buf to check the log
buf := new(bytes.Buffer)
Logger.Out = buf
root := NewOperation(context.Background(), "root")
var ctxFunc func(parent Operation, level int) Operation
levels := 10
ctxFunc = func(parent Operation, level int) Operation {
if level == levels {
return parent
}
child, _ := WithDeadline(&parent, time.Time{}, fmt.Sprintf("level %d", level))
return ctxFunc(child, level+1)
}
child := ctxFunc(root, 0)
// Assert the child has an error and prints a stack. The parent doesn't
// see this and should not have an error. Only cancelation trickles up the
// stack to the parent.
if !assert.NoError(t, root.Err()) || !assert.Error(t, child.Err()) {
return
}
// Assert we got a stack trace in the log
log := buf.String()
lines := strings.Count(log, "\n")
t.Log(log)
// Sample stack
//
// ERRO[0000] op=21598.101: github.com/vmware/vic/pkg/trace.TestNestedLogging: level 9 error: context deadline exceeded
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 9
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 8
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 7
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 6
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 5
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 4
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 3
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 2
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 1
// github.com/vmware/vic/pkg/trace.TestNestedLogging.func1:71 level 0
// github.com/vmware/vic/pkg/trace.TestNestedLogging:61 root
// We arrive at 2 because we have the err line (line 0), then the root
// (line 11) of where we created the ctx.
if assert.False(t, lines < levels) {
t.Logf("exepected at least %d and got %d", levels, lines)
return
}
}
// Just checking behavior of the context package
func TestSanity(t *testing.T) {
Logger.Level = logrus.InfoLevel
levels := 10
root, cancel := context.WithDeadline(context.Background(), time.Time{})
defer cancel()
var ctxFunc func(parent context.Context, level int) context.Context
ctxFunc = func(parent context.Context, level int) context.Context {
if level == levels {
return parent
}
child, cancel := context.WithDeadline(parent, time.Now().Add(time.Hour))
defer cancel()
return ctxFunc(child, level+1)
}
child := ctxFunc(root, 0)
if !assert.Error(t, child.Err()) {
t.FailNow()
}
err := root.Err()
if !assert.Error(t, err) {
return
}
}
// MockHook is a testify mock that can be registered as a logrus hook
type MockHook struct {
mock.Mock
}
// Levels indicates that the mock log hook supports all log levels
func (m *MockHook) Levels() []logrus.Level {
return logrus.AllLevels
}
// Fire records that it has been called and returns an error if configured
func (m *MockHook) Fire(entry *logrus.Entry) error {
args := m.Called(entry)
return args.Error(0)
}
// cases defines the set of messages we expect to see and the level we expect to see each at
var cases = map[string]logrus.Level{
"DebugfMessage": logrus.DebugLevel,
"DebugMessage": logrus.DebugLevel,
"InfofMessage": logrus.InfoLevel,
"InfoMessage": logrus.InfoLevel,
"WarnfMessage": logrus.WarnLevel,
"WarnMessage": logrus.WarnLevel,
"ErrorfMessage": logrus.ErrorLevel,
"ErrorMessage": logrus.ErrorLevel,
}
// buildMatcher creates a testify MatchedBy function for the supplied operation
func buildMatcher(op Operation, shouldContainOpID bool) func(entry *logrus.Entry) bool {
return func(entry *logrus.Entry) bool {
if shouldContainOpID && !strings.Contains(entry.Message, op.id) {
return false // Log message should have contained the operation id, but did not
}
if !shouldContainOpID && strings.Contains(entry.Message, op.id) {
return false // Log message should not have contained the operation id, but did
}
for message, level := range cases {
if entry.Level == level && strings.Contains(entry.Message, message) {
return true
}
}
return false
}
}
// TestLogging demonstrates that log messages are relayed from the Operation to the Logger global
func TestLogging(t *testing.T) {
defer func(original *logrus.Logger) { Logger = original }(Logger)
Logger = logrus.New()
op := NewOperation(context.Background(), "TestOperation")
m := new(MockHook)
Logger.Hooks.Add(m)
Logger.Level = logrus.DebugLevel
m.On("Fire", mock.MatchedBy(buildMatcher(op, true))).Return(nil)
op.Debugf("DebugfMessage")
op.Debug("DebugMessage")
op.Infof("InfofMessage")
op.Info("InfoMessage")
op.Warnf("WarnfMessage")
op.Warn("WarnMessage")
op.Errorf("ErrorfMessage")
op.Error(fmt.Errorf("ErrorMessage"))
m.AssertExpectations(t)
m.AssertNumberOfCalls(t, "Fire", 8)
}
// TestLogMuxing verifies that an operation-specific Logger can be configured and that both it and
// the global Logger receive messages when logging methods are called on Operation
func TestLogMuxing(t *testing.T) {
defer func(original *logrus.Logger) { Logger = original }(Logger)
Logger = logrus.New()
op := NewOperation(context.Background(), "TestOperation")
gm := new(MockHook)
Logger.Hooks.Add(gm)
Logger.Level = logrus.DebugLevel
lm := new(MockHook)
op.Logger = logrus.New()
op.Logger.Hooks.Add(lm)
op.Logger.Level = logrus.DebugLevel
gm.On("Fire", mock.MatchedBy(buildMatcher(op, true))).Return(nil)
lm.On("Fire", mock.MatchedBy(buildMatcher(op, false))).Return(nil)
op.Debugf("DebugfMessage")
op.Debug("DebugMessage")
op.Infof("InfofMessage")
op.Info("InfoMessage")
op.Warnf("WarnfMessage")
op.Warn("WarnMessage")
op.Errorf("ErrorfMessage")
op.Error(fmt.Errorf("ErrorMessage"))
gm.AssertExpectations(t)
gm.AssertNumberOfCalls(t, "Fire", 8)
lm.AssertExpectations(t)
lm.AssertNumberOfCalls(t, "Fire", 8)
}
// TestLogIsolation verifies that an operation-specific Loggers are actually operation-specific
func TestLogIsolation(t *testing.T) {
op1 := NewOperation(context.Background(), "TestOperation")
op2 := NewOperation(context.Background(), "TestOperation")
lm1 := new(MockHook)
op1.Logger = logrus.New()
op1.Logger.Hooks.Add(lm1)
op1.Logger.Level = logrus.DebugLevel
lm2 := new(MockHook)
op2.Logger = logrus.New()
op2.Logger.Hooks.Add(lm2)
op2.Logger.Level = logrus.DebugLevel
lm1.On("Fire", mock.MatchedBy(buildMatcher(op1, false))).Return(nil)
op1.Debugf("DebugfMessage")
op1.Info("InfoMessage")
op1.Warnf("WarnfMessage")
op1.Errorf("ErrorfMessage")
op1.Error(fmt.Errorf("ErrorMessage"))
lm1.AssertExpectations(t)
lm1.AssertNumberOfCalls(t, "Fire", 5)
lm2.AssertExpectations(t)
lm2.AssertNumberOfCalls(t, "Fire", 0)
}
// TestLogInheritance verifies that an operation-specific Loggers are inherited by children
func TestLogInheritance(t *testing.T) {
op := NewOperation(context.Background(), "TestOperation")
lm := new(MockHook)
op.Logger = logrus.New()
op.Logger.Hooks.Add(lm)
op.Logger.Level = logrus.DebugLevel
c1, _ := WithCancel(&op, "CancelChild")
c2 := WithValue(&c1, "foo", "bar", "ValueChild")
c3 := FromOperation(c2, "NormalChild")
c4 := FromContext(c3, "(Should == c3)")
lm.On("Fire", mock.MatchedBy(buildMatcher(op, false))).Return(nil)
op.Debugf("DebugfMessage")
c1.Infof("InfofMessage")
c2.Warnf("WarnfMessage")
c3.Errorf("ErrorfMessage")
c4.Error("ErrorMessage")
lm.AssertExpectations(t)
lm.AssertNumberOfCalls(t, "Fire", 5)
}

143
vendor/github.com/vmware/vic/pkg/trace/trace.go generated vendored Normal file
View File

@@ -0,0 +1,143 @@
// Copyright 2016-2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trace
import (
"context"
"fmt"
"os"
"runtime"
"strings"
"time"
"github.com/Sirupsen/logrus"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/vic/pkg/log"
)
var tracingEnabled = true
// Enable global tracing.
func EnableTracing() {
tracingEnabled = true
}
// Disable global tracing.
func DisableTracing() {
tracingEnabled = false
}
var Logger = &logrus.Logger{
Out: os.Stderr,
// We're using our own text formatter to skip the \n and \t escaping logrus
// was doing on non TTY Out (we redirect to a file) descriptors.
Formatter: log.NewTextFormatter(),
Hooks: make(logrus.LevelHooks),
Level: logrus.InfoLevel,
}
// trace object used to grab run-time state
type Message struct {
msg string
funcName string
lineNo int
operationID string
startTime time.Time
}
func (t *Message) delta() time.Duration {
if t == nil {
return 0
}
return time.Now().Sub(t.startTime)
}
// Add Syslog hook
// This method is not thread safe, this is currently
// not a problem because it is only called once from main
func InitLogger(cfg *log.LoggingConfig) error {
hook, err := log.CreateSyslogHook(cfg)
if err == nil && hook != nil {
Logger.Hooks.Add(hook)
}
return err
}
// begin a trace from this stack frame less the skip.
func newTrace(msg string, skip int, opID string) *Message {
pc, _, line, ok := runtime.Caller(skip)
if !ok {
return nil
}
// lets only return the func name from the repo (vic)
// down - i.e. vic/lib/etc vs. github.com/vmware/vic/lib/etc
// if github.com/vmware doesn't match then the original is returned
name := strings.TrimPrefix(runtime.FuncForPC(pc).Name(), "github.com/vmware/")
message := Message{
msg: msg,
funcName: name,
lineNo: line,
startTime: time.Now(),
}
// if we have an operationID then format the output
if opID != "" {
message.operationID = fmt.Sprintf("op=%s", opID)
}
return &message
}
// Begin starts the trace. Msg is the msg to log.
// context provided to allow tracing of operationID
// context added as optional to avoid breaking current usage
func Begin(msg string, ctx ...context.Context) *Message {
if tracingEnabled && Logger.Level >= logrus.DebugLevel {
var opID string
// populate operationID if provided
if len(ctx) == 1 {
if id, ok := ctx[0].Value(types.ID{}).(string); ok {
opID = id
}
}
if t := newTrace(msg, 2, opID); t != nil {
if msg == "" {
Logger.Debugf("[BEGIN] %s [%s:%d]", t.operationID, t.funcName, t.lineNo)
} else {
Logger.Debugf("[BEGIN] %s [%s:%d] %s", t.operationID, t.funcName, t.lineNo, t.msg)
}
return t
}
}
return nil
}
// End ends the trace.
func End(t *Message) {
if t == nil {
return
}
Logger.Debugf("[ END ] %s [%s:%d] [%s] %s", t.operationID, t.funcName, t.lineNo, t.delta(), t.msg)
}
func SetLogLevel(level uint8) {
Logger.Level = logrus.Level(level)
}