add --debug to show queries and error details
This commit is contained in:
parent
d71e91c58e
commit
b4782ce6ac
3 changed files with 9 additions and 1 deletions
2
main.go
2
main.go
|
@ -49,6 +49,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
||||||
parser := argparse.NewParser("hub", "hub server and client")
|
parser := argparse.NewParser("hub", "hub server and client")
|
||||||
|
|
||||||
serveCmd := parser.NewCommand("serve", "start the hub server")
|
serveCmd := parser.NewCommand("serve", "start the hub server")
|
||||||
|
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
|
||||||
|
|
||||||
host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "RPC host", Default: defaultHost})
|
host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "RPC host", Default: defaultHost})
|
||||||
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "RPC port", Default: defaultPort})
|
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "RPC port", Default: defaultPort})
|
||||||
|
@ -79,6 +80,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
||||||
EsHost: *esHost,
|
EsHost: *esHost,
|
||||||
EsPort: *esPort,
|
EsPort: *esPort,
|
||||||
EsIndex: *esIndex,
|
EsIndex: *esIndex,
|
||||||
|
Debug: *debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
if esHost, ok := environment["ELASTIC_HOST"]; ok {
|
if esHost, ok := environment["ELASTIC_HOST"]; ok {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -146,7 +147,11 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
|
||||||
var client *elastic.Client = nil
|
var client *elastic.Client = nil
|
||||||
if s.EsClient == nil {
|
if s.EsClient == nil {
|
||||||
esUrl := s.Args.EsHost + ":" + s.Args.EsPort
|
esUrl := s.Args.EsHost + ":" + s.Args.EsPort
|
||||||
tmpClient, err := elastic.NewClient(elastic.SetURL(esUrl), elastic.SetSniff(false))
|
opts := []elastic.ClientOptionFunc{elastic.SetSniff(false), elastic.SetURL(esUrl)}
|
||||||
|
if s.Args.Debug {
|
||||||
|
opts = append(opts, elastic.SetTraceLog(log.New(os.Stderr, "[[ELASTIC]]", 0)))
|
||||||
|
}
|
||||||
|
tmpClient, err := elastic.NewClient(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -25,6 +25,7 @@ type Args struct {
|
||||||
EsHost string
|
EsHost string
|
||||||
EsPort string
|
EsPort string
|
||||||
EsIndex string
|
EsIndex string
|
||||||
|
Debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue