From 280fa72b5058b2a3dfc00a53c0dd5751ec4f658c Mon Sep 17 00:00:00 2001 From: Alexander Ewetumo Date: Tue, 31 Oct 2017 16:32:25 +0100 Subject: [PATCH] Update readme and usage info --- README.md | 12 ++++++------ main.go | 19 ++++--------------- stats/read.go | 22 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4e58f5d..6f561ac 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,20 @@ Msgstat Msgstat provides a CLI tool which analyses status-go log files and generates corresponding output of information related to messages delivered over whisper (either rpc or p2p). -## Commands +## Usage -### `read` +Msgstat provides the processing functionality for the processing of all log files which would be used to produced aggregated collection of message delivery facts. -The command `read` provides the processing functionality for the processing of all log files which would be used to produced aggregated collection of message delivery facts. - -The `read` command expects processing data to be delivered either through sending given logs through `stdin` or through the use of the `file` flag. +It by defaults expects processing data to be delivered either through sending given logs through `stdin` or through the use of the `file` flag. - Processing log lines through stdin + ```bash -> cat ./logs/status-im/status-go/11.21.2017.log | msgstat read +> cat ./logs/status-im/status-go/11.21.2017.log | msgstat ``` - Processing log lines from a file + ```bash > msgstat read -file=./logs/status-im/status-go/11.21.2017.log ``` diff --git a/main.go b/main.go index 5dfc00f..5144e92 100644 --- a/main.go +++ b/main.go @@ -110,21 +110,10 @@ Msgstat processes status-go lines to generate useful message delivery facts. EXAMPLES: - 1. Read from stdin - - cat ./statusim/status.log | msgstat read - - 2. Read from file - - msgstat read -file=./statusim/status.log - - 3. Read from file and write to output file - - msgstat read -file=./statusim/status.log -out=./processed-log.json - - 4. Read from file and write in yaml format - - msgstat read -format=yaml -file=./statusim/status.log -out=./processed-log.json + cat status.log | msgstat # read from stdin + msgstat -file=status.log # read from file + msgstat -file=status.log -out=proc.json # read from file and write to output file + msgstat -format=yaml -file=status.log -out=proc.json # read from file and write in yaml format FLAGS: diff --git a/stats/read.go b/stats/read.go index 0aee2df..414a756 100644 --- a/stats/read.go +++ b/stats/read.go @@ -1,6 +1,10 @@ package stats -import "io" +import ( + "bufio" + "fmt" + "io" +) // AggregateLogs processes incoming data from the reader and writes appropriate // data with respect to format required. @@ -8,5 +12,21 @@ func AggregateLogs(r io.ReadCloser, w io.WriteCloser, format string) error { defer w.Close() defer r.Close() + bufReader := bufio.NewReader(r) + + for { + line, _, err := bufReader.ReadLine() + + // if we have reach end of file, just return. + if err != nil { + if err == io.EOF { + return nil + } + + return err + } + + fmt.Printf("Currentline: %+q", line) + } return nil }