func main() { fields := flag.String("fields", "", "json-encoded map of fields") out := flag.String("out", "", "output file to use instead of stdout") interval := flag.Int("i", 1, "interval to check for log rotation") flag.Parse() extra, err := parseFields(*fields) if err != nil { log.Fatal(err) } o, err := getOutput(*out, *interval) if err != nil { log.Fatal(err) } w := logstasher.NewWriter(o, extra) s := bufio.NewScanner(os.Stdin) for s.Scan() { _, err := w.Write(s.Bytes()) if err != nil { log.Fatal(err) } } if err := s.Err(); err != nil { log.Fatal(err) } }
func ExampleWriter() { f := map[string]interface{}{ "app": "myapp", "things": []string{"something", "another"}, } w := logstasher.NewWriter(os.Stdout, f) log.SetFlags(0) log.SetOutput(w) log.Println("hey, logstash!") }