github.com/annchain/OG@v0.0.9/tests/testLogger/logger_test.go (about)

     1  package testLogger
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/annchain/OG/arefactor/og/types"
     6  	"github.com/annchain/OG/common"
     7  	"github.com/sirupsen/logrus"
     8  	"testing"
     9  )
    10  
    11  func TestLogger(t *testing.T) {
    12  	logrus.SetLevel(logrus.DebugLevel)
    13  	foo := randomFoo()
    14  	foo2 := *randomFoo()
    15  	fmt.Println("func 1")
    16  	logrus.WithField("tx", foo).Tracef("bad tx")
    17  	fmt.Println("func 2")
    18  	logrus.WithField("tx", foo.String()).Trace("parent  is bad")
    19  	fmt.Println("func 3")
    20  	logrus.WithField("tx", foo2).Tracef("bad tx")
    21  	fmt.Println("func 4")
    22  	logrus.WithField("tx", foo2.String()).Tracef("parent is bad")
    23  	fmt.Println("func 5")
    24  	f := foo.Bar
    25  	if logrus.GetLevel() > logrus.DebugLevel {
    26  		logrus.WithField("bar ", f()).Tracef("bar")
    27  	}
    28  	fmt.Println("func 6")
    29  
    30  	logrus.WithField("bar ", f()).Tracef("bar")
    31  	fmt.Println("func 7")
    32  	logrus.Tracef("parent is bad %s", foo2)
    33  	fmt.Println("func 8")
    34  	logrus.Tracef("parent is bad %s", foo2.String())
    35  
    36  }
    37  
    38  type Foo struct {
    39  	Hash types.Hash
    40  	Add  common.Address
    41  	Name string
    42  	Id   uint64
    43  }
    44  
    45  func (f Foo) String() string {
    46  
    47  	fmt.Println("this function is called")
    48  	s := fmt.Sprintf("[%v-%v-%v-%v]", f.Hash.String(), f.Add.String(), f.Name, f.Id)
    49  	fmt.Println("this function is called with return value ", s)
    50  	//logrus.Debugf("hash %v",f.Hash)
    51  	//logrus.Debugf("hash %v",f.Hash.String())
    52  	return s
    53  }
    54  
    55  func (f *Foo) Bar() uint32 {
    56  	fmt.Println("bar is called")
    57  	return 32
    58  }
    59  
    60  var globalInt uint64
    61  
    62  func randomFoo() *Foo {
    63  	globalInt++
    64  	return &Foo{
    65  		Hash: types.RandomHash(),
    66  		Add:  types.RandomAddress(),
    67  		Name: "test",
    68  		Id:   globalInt,
    69  	}
    70  }