...

Source file src/edge-infra.dev/pkg/lib/cli/clog/example_test.go

Documentation: edge-infra.dev/pkg/lib/cli/clog

     1  package clog
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  )
     7  
     8  var errSome = errors.New("some error")
     9  
    10  func ExampleNew() {
    11  	log := New(To(os.Stdout))
    12  	log.Info("info message with default options")
    13  	log.Error(errSome, "error message with default options")
    14  	log.Info("invalid key", 42, "answer")
    15  	log.Info("missing value", "answer")
    16  	log.Info("logging some maps",
    17  		"map1", map[string]string{"key": "value", "op": "delete"},
    18  		"map2", map[string]string{"feeling": "less than map1", "key": "value"},
    19  	)
    20  	log.WithName("cli").WithName("subcommand").Info("coming from the deep", "kubectx", "ci-infra")
    21  	// Output:
    22  	// info message with default options
    23  	// [error] <pkg/lib/cli/clog/example_test.go:13> error message with default options
    24  	//     err=some error
    25  	// invalid key !(42)=answer
    26  	// missing value answer=null
    27  	// logging some maps
    28  	//   map1=
    29  	//     key  value
    30  	//     op   delete
    31  	//   map2=
    32  	//     feeling  less than map1
    33  	//     key      value
    34  	// cli:subcommand: coming from the deep kubectx=ci-infra
    35  }
    36  
    37  func ExampleNew_withCaller() {
    38  	// Add caller information to all logs
    39  	log := New(To(os.Stdout), WithCaller(All))
    40  	log.WithName("hello").WithName("world").Info("thanks for the fish")
    41  	// Output:
    42  	// hello:world: <pkg/lib/cli/clog/example_test.go:40> thanks for the fish
    43  }
    44  

View as plain text