Skip to content

Commit

Permalink
Add close method
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Nov 14, 2016
1 parent 1fb3829 commit 707dc88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/godmesg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
)

func main() {
kmsgParser, err := kmsgparser.NewParser()
parser, err := kmsgparser.NewParser()
if err != nil {
log.Fatalf("unable to create parser: %v", err)
}
defer parser.Close()

kmsg := kmsgParser.Parse()
kmsg := parser.Parse()

for msg := range kmsg {
fmt.Printf("(%d) - %s: %s", msg.SequenceNumber, msg.Timestamp.Format(time.RFC3339Nano), msg.Message)
Expand Down
6 changes: 6 additions & 0 deletions kmsgparser/kmsgparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Parser interface {
// SetLogger sets the logger that will be used to report malformed kernel
// ringbuffer lines or unexpected kmsg read errors.
SetLogger(Logger)
// Close closes the underlying kmsg reader for this parser
Close() error
}

// Message represents a given kmsg logline, including its timestamp (as
Expand Down Expand Up @@ -90,6 +92,10 @@ func (p *parser) SetLogger(log Logger) {
p.log = log
}

func (p *parser) Close() error {
return p.kmsgReader.Close()
}

// Parse will read from the provided reader and provide a channel of messages
// parsed.
// If the provided reader *is not* a proper Linux kmsg device, Parse might not
Expand Down

0 comments on commit 707dc88

Please sign in to comment.