1
0

Show last log if no ID specified

This commit is contained in:
dump_stack() 2020-06-14 20:46:56 +00:00
parent 22a8e32e2c
commit 992c41c84b
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
4 changed files with 28 additions and 2 deletions

View File

@ -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

18
db.go
View File

@ -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 {

7
log.go
View File

@ -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
}

View File

@ -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()