Commit 60758216 authored by ale's avatar ale

Add --iso option to format timestamps according to RFC3339

parent 86a3c168
Pipeline #1117 passed with stages
in 1 minute 1 second
......@@ -23,15 +23,36 @@ import (
)
var (
elasticURL = flag.String("url", "http://127.0.0.1:9200", "Elasticsearch URL")
fromDate = flag.String("from", "-1h", "start `date`")
toDate = flag.String("to", "", "end `date` (default now, otherwise relative to --from)")
doDumpQuery = flag.Bool("dump-query", false, "don't do anything, just print the ES query as JSON")
batchSize = flag.Int("batch-size", 10000, "ES scroll batch `size`")
indexFmt = flag.String("index-format", "logstash-2006.01.02", "ES index `format` string, as supported by Go time.Format()")
objType = flag.String("obj-type", "events", "ES index object `type`")
elasticURL = flag.String("url", "http://127.0.0.1:9200", "Elasticsearch URL")
fromDate = flag.String("from", "-1h", "start `date`")
toDate = flag.String("to", "", "end `date` (default now, otherwise relative to --from)")
doDumpQuery = flag.Bool("dump-query", false, "don't do anything, just print the ES query as JSON")
batchSize = flag.Int("batch-size", 10000, "ES scroll batch `size`")
indexFmt = flag.String("index-format", "logstash-2006.01.02", "ES index `format` string, as supported by Go time.Format()")
objType = flag.String("obj-type", "events", "ES index object `type`")
isoTimestamps = flag.Bool("iso", false, "dump ISO timestamps")
)
func usage() {
// nolint: errcheck
fmt.Fprintf(os.Stderr, `Usage: logcat [<options>] <query>...
Query a syslog database on Elasticsearch.
This tool can query Logstash-like archives stored on Elasticsearch
that contain syslog logs. Use the --url option to select the ES
server to talk to.
The command-line arguments should contain an Elasticsearch query,
in the standard QueryString syntax.
The output is not necessarily sorted by timestamp.
Known options:
`)
flag.PrintDefaults()
}
var allowedTimeFormats = []string{
time.RFC3339,
time.RFC822,
......@@ -103,7 +124,12 @@ type logMessage struct {
}
func (m *logMessage) format() string {
ts := m.Timestamp.Format(time.Stamp)
var ts string
if *isoTimestamps {
ts = m.Timestamp.Format(time.RFC3339)
} else {
ts = m.Timestamp.Format(time.Stamp)
}
if m.Tag == "" {
return fmt.Sprintf("%s %s%s\n", ts, m.Host, m.Message)
}
......@@ -253,6 +279,7 @@ func (s *batchSender) Close() {
func main() {
log.SetFlags(0)
flag.Usage = usage
flag.Parse()
from, to, err := parseTimeRange(*fromDate, *toDate)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment