Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add '--raw' flag to output JSON lines #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type SearchTarget struct {
type QueryDefinition struct {
Terms []string
Format string
Raw bool
TimestampField string
AfterDateTime string `json:"-"`
BeforeDateTime string `json:"-"`
Expand Down Expand Up @@ -159,6 +160,11 @@ func (config *Configuration) Flags() []cli.Flag {
Usage: "(*) Message format for the entries - field names are referenced using % sign, for example '%@timestamp %message'",
Destination: &config.QueryDefinition.Format,
},
cli.BoolFlag{
Name: "raw",
Usage: "Just print raw JSON lines",
Destination: &config.QueryDefinition.Raw,
},
cli.StringFlag{
Name: "i,index-pattern",
Value: "logstash-[0-9].*",
Expand Down
10 changes: 8 additions & 2 deletions elktail.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,14 @@ func (t *Tail) processHit(hit *elastic.SearchHit) map[string]interface{} {
if err != nil {
Error.Fatalln("Failed parsing ElasticSearch response.", err)
}
t.printResult(entry)
return entry;

if t.queryDefinition.Raw {
fmt.Println(string(*hit.Source))
} else {
t.printResult(entry)
}

return entry
}


Expand Down