X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-log%2Fmain.go;h=0ad3888415f6fdfab24c31502a6296e2d902fdce;hb=7c507e7ddba9fe5557df06c860fe9fa6197ba2e1;hp=883d06f416aa4ebfaedc2a83fcbaa75035258787;hpb=1d2ce674b042d07fd9b37a46578c8b62bb0345b7;p=nncp.git diff --git a/src/cmd/nncp-log/main.go b/src/cmd/nncp-log/main.go index 883d06f..0ad3888 100644 --- a/src/cmd/nncp-log/main.go +++ b/src/cmd/nncp-log/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2019 Sergey Matveev +Copyright (C) 2016-2023 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,18 +19,18 @@ along with this program. If not, see . package main import ( - "bufio" "flag" "fmt" + "io" "log" "os" - "go.cypherpunks.ru/nncp/v5" + "go.cypherpunks.ru/nncp/v8" + "go.cypherpunks.ru/recfile" ) func usage() { - fmt.Fprintf(os.Stderr, nncp.UsageHeader()) - fmt.Fprintf(os.Stderr, "nncp-log -- read logs\n\n") + fmt.Fprint(os.Stderr, "nncp-log -- read logs\n\n") fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } @@ -43,6 +43,7 @@ func main() { version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) + log.SetFlags(log.Lshortfile) flag.Usage = usage flag.Parse() if *warranty { @@ -63,15 +64,22 @@ func main() { if err != nil { log.Fatalln("Can not open log:", err) } - scanner := bufio.NewScanner(fd) - for scanner.Scan() { - t := scanner.Text() + r := recfile.NewReader(fd) + for { + le, err := r.NextMap() + if err != nil { + if err == io.EOF { + break + } + log.Fatalln("Can not read log:", err) + } if *debug { - fmt.Println(t) + fmt.Println(le) } - fmt.Println(ctx.Humanize(t)) - } - if err = scanner.Err(); err != nil { - log.Fatalln("Can not read log:", err) + s, err := ctx.Humanize(le) + if err != nil { + s = fmt.Sprintf("Can not humanize: %s\n%s", err, le) + } + fmt.Println(s) } }