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

Function main

_examples/logging/custom.go:101–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99func (l *CustomLogger) ResponseBodyEnabled() bool { return true }
100
101func main() {
102
103 // ==============================================================================================
104 //
105 // Set up a logger
106 //
107 log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).
108 Level(zerolog.InfoLevel).
109 With().
110 Timestamp().
111 Logger()
112
113 // ==============================================================================================
114 //
115 // Pass the logger to the client
116 //
117 es, _ := elasticsearch.New(elasticsearch.WithLogger(&CustomLogger{log}))
118 defer func() {
119 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
120 defer cancel()
121 if err := es.Close(ctx); err != nil {
122 log.Fatal().Err(err).Msg("Error closing the client")
123 }
124 }()
125
126 // ----------------------------------------------------------------------------------------------
127 {
128 es.Delete("test", "1")
129 es.Exists("test", "1")
130 es.Index("test", strings.NewReader(`{"title" : "logging"}`), es.Index.WithRefresh("true"))
131
132 es.Search(
133 es.Search.WithQuery("{FAIL"),
134 )
135
136 es.Search(
137 es.Search.WithIndex("test"),
138 es.Search.WithBody(strings.NewReader(`{"query" : {"match" : { "title" : "logging" } } }`)),
139 es.Search.WithSize(1),
140 )
141 }
142}

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.65
TimestampMethod · 0.45
LevelMethod · 0.45
WithTimeoutMethod · 0.45
DeleteMethod · 0.45
ExistsMethod · 0.45
IndexMethod · 0.45
WithRefreshMethod · 0.45
SearchMethod · 0.45
WithQueryMethod · 0.45
WithIndexMethod · 0.45
WithBodyMethod · 0.45

Tested by

no test coverage detected