From 2d7d4b1006a8cd1f7af6244672541e9ac16bfac9 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 8 Apr 2020 07:18:26 -0700 Subject: [PATCH] add tool to see log entries --- unmaintained/see_log_entry/see_log_entry.go | 74 +++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 unmaintained/see_log_entry/see_log_entry.go diff --git a/unmaintained/see_log_entry/see_log_entry.go b/unmaintained/see_log_entry/see_log_entry.go new file mode 100644 index 000000000..b7d724344 --- /dev/null +++ b/unmaintained/see_log_entry/see_log_entry.go @@ -0,0 +1,74 @@ +package main + +import ( + "flag" + "fmt" + "io" + "log" + "os" + + "github.com/golang/protobuf/proto" + + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "github.com/chrislusf/seaweedfs/weed/util" +) + +var ( + logdataFile = flag.String("logdata", "", "log data file saved under /.meta/log/...") +) + +func main() { + flag.Parse() + + dst, err := os.OpenFile(*logdataFile, os.O_RDONLY, 0644) + if err != nil { + log.Fatalf("failed to open %s: %v", *logdataFile, err) + } + defer dst.Close() + + err = walkLogEntryFile(dst) + if err != nil { + log.Fatalf("failed to visit %s: %v", *logdataFile, err) + } + +} + +func walkLogEntryFile(dst *os.File) error { + + sizeBuf := make([]byte, 4) + + for { + if n, err := dst.Read(sizeBuf); n != 4 { + if err == io.EOF { + return nil + } + return err + } + + size := util.BytesToUint32(sizeBuf) + + data := make([]byte, int(size)) + + if n, err := dst.Read(data); n != len(data) { + return err + } + + logEntry := &filer_pb.LogEntry{} + err := proto.Unmarshal(data, logEntry) + if err != nil { + log.Printf("unexpected unmarshal filer_pb.LogEntry: %v", err) + return nil + } + + event := &filer_pb.FullEventNotification{} + err = proto.Unmarshal(logEntry.Data, event) + if err != nil { + log.Printf("unexpected unmarshal filer_pb.FullEventNotification: %v", err) + return nil + } + + fmt.Printf("event: %+v\n", event) + + } + +}