Browse Source

Show last log if no ID specified

master
dump_stack() 2 years ago
parent
commit
992c41c84b
Signed by: dump_stack GPG Key ID: BE44DA8C062D87DC
  1. 3
      CHANGELOG.md
  2. 18
      db.go
  3. 7
      log.go
  4. 2
      main.go

3
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

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

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

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

Loading…
Cancel
Save