...

Source file src/cdr.dev/slog/example_helper_test.go

Documentation: cdr.dev/slog

     1  package slog_test
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"os"
     7  
     8  	"cdr.dev/slog"
     9  	"cdr.dev/slog/sloggers/sloghuman"
    10  )
    11  
    12  func httpLogHelper(ctx context.Context, status int) {
    13  	slog.Helper()
    14  
    15  	l.Info(ctx, "sending HTTP response",
    16  		slog.F("status", status),
    17  	)
    18  }
    19  
    20  var l = slog.Make(sloghuman.Sink(os.Stdout))
    21  
    22  func ExampleHelper() {
    23  	ctx := context.Background()
    24  	httpLogHelper(ctx, http.StatusBadGateway)
    25  
    26  	// 2019-12-07 21:18:42.567 [INFO]	<example_helper_test.go:24>	sending HTTP response	{"status": 502}
    27  }
    28  

View as plain text