github.com/weedge/lib@v0.0.0-20230424045628-a36dcc1d90e4/log/example_test.go (about)

     1  package log
     2  
     3  import (
     4  	"go.uber.org/zap"
     5  )
     6  
     7  func Example_Info() {
     8  	Info("123123", "adfasdf")
     9  	Debug("123123", "adfasdf")
    10  	Warn("123123", "adfasdf")
    11  	Error("123123", "adfasdf")
    12  	RpcInfo("123123", "rpc")
    13  	Recover("123123", "recover")
    14  
    15  	// output:
    16  	//
    17  }
    18  
    19  func Example_Infof() {
    20  	Infof("%s, %s", "123123", "adfasdf")
    21  	Debugf("%s, %s", "123123", "adfasdf")
    22  	Warnf("%s, %s", "123123", "adfasdf")
    23  	Errorf("%s, %s", "123123", "adfasdf")
    24  	BizArchive("%s, %s", "123123", "biz")
    25  	RpcInfof("%s, %s", "123123", "rpc")
    26  	Recoverf("%s, %s", "123123", "recover")
    27  
    28  	// output:
    29  	//
    30  }
    31  
    32  func ExampleAccessInfo() {
    33  	fields := []zap.Field{
    34  		zap.String(LOGID, "123123"),
    35  		zap.String(URI, "/source/get"),
    36  		zap.String(REFERER, "www.google.com"),
    37  		zap.Any(COOKIE, "cookie:1231"),
    38  		zap.String(CLIENT_IP, "192.168.7.3"),
    39  		zap.String(LOCAL_IP, LOCALIP),
    40  		zap.String(UA, "web-chrome"),
    41  		zap.String(HOST, "www.baidu.com"),
    42  		zap.String(MODULE, "live"),
    43  		zap.String("request_param", "a=1&b=2"),
    44  		zap.String(NOTICES, "notices"),
    45  		zap.String(MONITOR, "{'monitor':true}"),
    46  		zap.Int(CODE, 200),
    47  		zap.String(RESPONSE, "response"),
    48  		zap.Int64(COST, 100),
    49  	}
    50  	AccessInfo("", fields...)
    51  
    52  	// output:
    53  	//
    54  }
    55  
    56  func ExampleSetup() {
    57  	err := Setup("testProject", "./", "./log", nil)
    58  	if err != nil {
    59  		println(err)
    60  	}
    61  	Example_Info()
    62  	Example_Infof()
    63  	ExampleAccessInfo()
    64  
    65  	// output:
    66  	//
    67  }