X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-log%2Fmain.go;h=dbe03b8d20bbbba943ea29ec6ddf7031f8bfa65b;hb=0367cce2741e1ce6a89a49fd5c4e9df6005c9744;hp=74062610aa93cb8db189847aa023c86d9617421c;hpb=fa24572f1280b56977c6dcf6969a736403d1280e;p=nncp.git diff --git a/src/cmd/nncp-log/main.go b/src/cmd/nncp-log/main.go index 7406261..dbe03b8 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-2021 Sergey Matveev +Copyright (C) 2016-2022 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,13 +19,14 @@ 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() { @@ -43,6 +44,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 +65,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) } }