MCPcopy
hub / github.com/elastic/go-elasticsearch / main

Function main

_examples/logging/default.go:40–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38)
39
40func main() {
41 log.SetFlags(0)
42
43 var es *elasticsearch.Client
44
45 // ==============================================================================================
46 //
47 // "TextLogger" writes basic information about the request and response as plain text to the output.
48 //
49 es, _ = elasticsearch.New(elasticsearch.WithLogger(&elastictransport.TextLogger{Output: os.Stdout}))
50 run(es, "Text")
51 _ = es.Close(context.Background())
52
53 // ==============================================================================================
54 //
55 // "ColorLogger" is optimized for displaying information in the terminal during development.
56 //
57 es, _ = elasticsearch.New(elasticsearch.WithLogger(&elastictransport.ColorLogger{Output: os.Stdout}))
58 run(es, "Color")
59 _ = es.Close(context.Background())
60
61 // ==============================================================================================
62 //
63 // To log the request and response bodies, use the respective configuration options.
64 //
65 es, _ = elasticsearch.New(elasticsearch.WithLogger(&elastictransport.ColorLogger{
66 Output: os.Stdout,
67 EnableRequestBody: true,
68 EnableResponseBody: true,
69 }))
70 run(es, "Request/Response Body")
71 _ = es.Close(context.Background())
72
73 // ==============================================================================================
74 //
75 // "CurlLogger" writes the information formatted as runnable curl commands,
76 // pretty-printing the response body (when enabled), useful eg. for sharing.
77 //
78 es, _ = elasticsearch.New(elasticsearch.WithLogger(&elastictransport.CurlLogger{Output: os.Stdout, EnableRequestBody: true, EnableResponseBody: true}))
79 run(es, "Curl")
80 _ = es.Close(context.Background())
81
82 // ==============================================================================================
83 //
84 // "JSONLogger" writes the information as JSON and is suitable for production logging.
85 //
86 es, _ = elasticsearch.New(elasticsearch.WithLogger(&elastictransport.JSONLogger{Output: os.Stdout}))
87 run(es, "JSON")
88 _ = es.Close(context.Background())
89}
90
91// ------------------------------------------------------------------------------------------------
92

Callers

nothing calls this directly

Calls 2

runFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected