X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-log%2Fmain.go;h=73d09afa362d864fee50ac5b5c9205174dc4503f;hb=4ba3188c55713c2b3a2326ab6b670606f27a13f5;hp=97ca259e80fb907715f5a807e32f1d4d6fe77fe4;hpb=0139e8deda4112d2c3dcd52e0ad72162e54caa03;p=nncp.git diff --git a/src/cmd/nncp-log/main.go b/src/cmd/nncp-log/main.go index 97ca259..73d09af 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,19 @@ 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.UsageHeader()) + 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 +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 { @@ -54,7 +56,7 @@ func main() { return } - ctx, err := nncp.CtxFromCmdline(*cfgPath, "", *logPath, false, *debug) + ctx, err := nncp.CtxFromCmdline(*cfgPath, "", *logPath, false, false, false, *debug) if err != nil { log.Fatalln("Error during initialization:", err) } @@ -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) } }