From 992c41c84bd380088d22f0b2b2b43556401f2d16 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sun, 14 Jun 2020 20:46:56 +0000 Subject: [PATCH] Show last log if no ID specified --- CHANGELOG.md | 3 +++ db.go | 18 ++++++++++++++++++ log.go | 7 ++++++- main.go | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f9a3b..1a5fc7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ - Flag `--disable-preload` to ignore `[[preload]]` section of configuration file. +- Now `out-of-tree log dump` will show the last log if no ID + specified. + ## [1.3.0] 2020-05-30 ### Added diff --git a/db.go b/db.go index 94b32a4..71e9db9 100644 --- a/db.go +++ b/db.go @@ -254,6 +254,24 @@ func getLogByID(db *sql.DB, id int) (le logEntry, err error) { return } +func getLastLog(db *sql.DB) (le logEntry, err error) { + err = db.QueryRow("SELECT MAX(id), time, name, type, tag, "+ + "distro_type, distro_release, kernel_release, "+ + "build_ok, run_ok, test_ok, "+ + "build_output, run_output, test_output, "+ + "qemu_stdout, qemu_stderr, "+ + "kernel_panic, timeout_kill "+ + "FROM log").Scan(&le.ID, &le.Timestamp, + &le.Name, &le.Type, &le.Tag, + &le.DistroType, &le.DistroRelease, &le.KernelRelease, + &le.Build.Ok, &le.Run.Ok, &le.Test.Ok, + &le.Build.Output, &le.Run.Output, &le.Test.Output, + &le.Stdout, &le.Stderr, + &le.KernelPanic, &le.KilledByTimeout, + ) + return +} + func createSchema(db *sql.DB) (err error) { err = createMetadataTable(db) if err != nil { diff --git a/log.go b/log.go index 0ebf94d..90cf077 100644 --- a/log.go +++ b/log.go @@ -100,7 +100,12 @@ func logHandler(db *sql.DB, path, tag string, num int, rate bool) (err error) { } func logDumpHandler(db *sql.DB, id int) (err error) { - l, err := getLogByID(db, id) + var l logEntry + if id > 0 { + l, err = getLogByID(db, id) + } else { + l, err = getLastLog(db) + } if err != nil { return } diff --git a/main.go b/main.go index 07b851f..7c7c706 100644 --- a/main.go +++ b/main.go @@ -217,7 +217,7 @@ func main() { logDumpCommand := logCommand.Command("dump", "Show all info for log entry with ID") - logDumpID := logDumpCommand.Arg("ID", "").Required().Int() + logDumpID := logDumpCommand.Arg("ID", "").Default("-1").Int() logJSONCommand := logCommand.Command("json", "Generate json statistics") logJSONTag := logJSONCommand.Flag("tag", "Filter tag").Required().String()