seaweedfs/unmaintained/see_log_entry/see_log_entry.go

76 lines
1.4 KiB
Go
Raw Normal View History

2020-04-08 14:18:26 +00:00
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"github.com/golang/protobuf/proto"
2020-04-12 21:03:07 +00:00
"github.com/chrislusf/seaweedfs/weed/filer2"
2020-04-08 14:18:26 +00:00
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/util"
)
var (
2020-04-12 21:03:07 +00:00
logdataFile = flag.String("logdata", "", "log data file saved under "+ filer2.SystemLogDir)
2020-04-08 14:18:26 +00:00
)
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
}
2020-04-13 04:00:55 +00:00
event := &filer_pb.SubscribeMetadataResponse{}
2020-04-08 14:18:26 +00:00
err = proto.Unmarshal(logEntry.Data, event)
if err != nil {
2020-04-13 04:00:55 +00:00
log.Printf("unexpected unmarshal filer_pb.SubscribeMetadataResponse: %v", err)
2020-04-08 14:18:26 +00:00
return nil
}
fmt.Printf("event: %+v\n", event)
}
}