Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai3
tools
logcat
Commits
86a3c168
Commit
86a3c168
authored
Aug 06, 2018
by
ale
Browse files
Make --to relative to --from
parent
4e0f0803
Changes
1
Hide whitespace changes
Inline
Side-by-side
logcat.go
View file @
86a3c168
...
...
@@ -23,13 +23,13 @@ import (
)
var
(
elasticURL
=
flag
.
String
(
"url"
,
"http://127.0.0.1:9200"
,
"E
S
URL"
)
fromDate
=
flag
.
String
(
"from"
,
"-1h"
,
"start date"
)
toDate
=
flag
.
String
(
"to"
,
""
,
"end date (default now)"
)
elasticURL
=
flag
.
String
(
"url"
,
"http://127.0.0.1:9200"
,
"E
lasticsearch
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"
)
index
Base
=
flag
.
String
(
"index"
,
"logstash"
,
"ES index
base name
"
)
objType
=
flag
.
String
(
"obj-type"
,
"events"
,
"ES index object type"
)
batchSize
=
flag
.
Int
(
"batch-size"
,
10000
,
"ES scroll batch
`
size
`
"
)
index
Fmt
=
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
`
"
)
)
var
allowedTimeFormats
=
[]
string
{
...
...
@@ -40,7 +40,7 @@ var allowedTimeFormats = []string{
"2006/1/2"
,
}
func
parseTime
(
now
time
.
Time
,
s
string
)
(
t
time
.
Time
,
err
error
)
{
func
parseTime
(
base
time
.
Time
,
s
string
)
(
t
time
.
Time
,
err
error
)
{
var
d
time
.
Duration
switch
{
case
strings
.
HasPrefix
(
s
,
"+"
)
:
...
...
@@ -48,13 +48,13 @@ func parseTime(now time.Time, s string) (t time.Time, err error) {
if
err
!=
nil
{
return
}
t
=
now
.
Add
(
d
)
t
=
base
.
Add
(
d
)
case
strings
.
HasPrefix
(
s
,
"-"
)
:
d
,
err
=
time
.
ParseDuration
(
s
[
1
:
])
if
err
!=
nil
{
return
}
t
=
now
.
Add
(
-
d
)
t
=
base
.
Add
(
-
d
)
default
:
for
_
,
f
:=
range
allowedTimeFormats
{
t
,
err
=
time
.
Parse
(
f
,
s
)
...
...
@@ -82,7 +82,7 @@ func parseTimeRange(fromStr, toStr string) (from time.Time, to time.Time, err er
if
toStr
==
""
{
to
=
now
}
else
{
to
,
err
=
parseTime
(
now
,
toStr
)
to
,
err
=
parseTime
(
from
,
toStr
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error in --to: %v"
,
err
)
return
...
...
@@ -113,9 +113,8 @@ func (m *logMessage) format() string {
func
getIndexes
(
from
,
to
time
.
Time
)
[]
string
{
var
idxs
[]
string
t
:=
time
.
Date
(
from
.
Year
(),
from
.
Month
(),
from
.
Day
(),
0
,
0
,
0
,
0
,
time
.
UTC
)
idxFmt
:=
fmt
.
Sprintf
(
"%s-2006.01.02"
,
*
indexBase
)
for
t
.
Before
(
to
)
{
idxs
=
append
(
idxs
,
t
.
Format
(
id
xFmt
))
idxs
=
append
(
idxs
,
t
.
Format
(
*
inde
xFmt
))
t
=
t
.
AddDate
(
0
,
0
,
1
)
}
return
idxs
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment