Skip to content

Commit

Permalink
Add Timestamp option (#5)
Browse files Browse the repository at this point in the history
* add timestamp printout as optional

* time format to milliseconds

* update readme
  • Loading branch information
lczupryn-tibco authored Sep 26, 2022
1 parent 2ec5401 commit 1e5205b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builds/*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Options:
-q, --query <string> logql query [LOGQL_QUERY]
-t, --labels get labels
-v, --label <string> get label values
-z, --timestamp get timestamp
-s, --start <string> start nanosec timestamp
-e, --end <string> end nanosec timestamp
-x, --tail tail mode
Expand Down
15 changes: 13 additions & 2 deletions vlogql.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mut:
end string = '0'
labels bool
debug bool
ts bool
timer int
}

Expand Down Expand Up @@ -52,14 +53,21 @@ struct Values {
fn fetch_logs(app App) {
data := http.get_text('$app.api/loki/api/v1/query_range?query=$app.query&limit=$app.limit&start=$app.start&end=$app.end')
res := json.decode(Response, data) or { exit(1) }
println('---------- Logs for: $app.query')
println('---------- Logs for: $app.query')
for row in res.data.result {
if app.labels {
print(term.gray('Log Labels: '))
print(term.bold('$row.stream\n'))
}
for log in row.values {
println(log[1])
if app.ts {
ts_microseconds := ((log[0].i64())%1000000000)/1000
ts := time.unix2(log[0].i64()/1000000000,int(ts_microseconds))
println('${ts.format_ss_milli()}: ${log[1]}')
}
else{
println(log[1])
}
}
}
return
Expand Down Expand Up @@ -245,6 +253,9 @@ fn main() {
logql_labels := fp.bool('labels', `t`, false, 'get labels')
logql_label := fp.string('label', `v`, '', 'get label values')
app.labels = logql_labels

logql_timestamp := fp.bool('timestamp', `z`, false, 'get timestamp')
app.ts = logql_timestamp

logql_start := fp.string('start', `s`, now(3600), 'start nanosec timestamp')
logql_end := fp.string('end', `e`, now(0), 'end nanosec timestamp')
Expand Down

0 comments on commit 1e5205b

Please sign in to comment.