seaweedfs/unmaintained/see_log_entry/see_log_entry.go

76 lines
1.4 KiB
Go
Raw Normal View History

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