예제 #1
0
func (logger *fileLogger) logEvent(event eventlogger.Event) (err error) {
	file, err := logger.getTopicFile(event.Topic)
	if err != nil {
		return err
	}
	//if _, err = fmt.Fprintf(file, "[%37s] %10s\n", event.Time, event.Data); err != nil {
	var bytes []byte
	bytes, err = event.MarshalBinary()
	if err != nil {
		log.Printf("Error marshalling event, err: %s", err)
		return err
	}
	if _, err = file.Write(bytes); err != nil {
		log.Printf("Error writing event, err: %s", err)
	}
	return err
}
예제 #2
0
func main() {
	scanner := io.NewScanner(os.Stdin)
	path := flag.String("path", "topic", "path+filename")
	flag.Parse()
	file, err := os.Open(*path) // todo: path for topic
	if err != nil {
		log.Printf("Error opening file, path: %s, err: %s\n", *path, err)
		return
	}

	var recordNumber int
	for {
		//fmt.Print("\noffset length: ")
		fmt.Print("\nrecord number: ")

		//offset, err = scanner.ReadLong()
		recordNumber, err = scanner.ReadInt()
		if err != nil {
			fmt.Println("Enter an int\n")
			continue
		}
		//length, err = scanner.ReadInt()
		//if err != nil {
		//	fmt.Println("Enter an int\n")
		//	continue
		//}
		bytes := make([]byte, RECLEN)
		if _, err = file.ReadAt(bytes, int64(recordNumber)*RECLEN); err != nil {
			fmt.Println(err)
		} else {
			event := eventlogger.Event{}
			if err = event.UnmarshalBinary(bytes); err != nil {
				fmt.Println(err)
			} else {
				fmt.Println(event.ToString())
			}
		}
	}
}