func main() { g := cloudwatch.NewGroup("test", cloudwatchlogs.New(defaults.DefaultConfig)) stream := uuid.New() w, err := g.Create(stream) if err != nil { log.Fatal(err) } r, err := g.Open(stream) if err != nil { log.Fatal(err) } go func() { var i int for { i++ <-time.After(time.Second / 30) _, err := fmt.Fprintf(w, "Line %d\n", i) if err != nil { log.Println(err) } } }() io.Copy(os.Stdout, r) }
// RecordToCloudWatch returns a RunRecorder that writes the log record to // CloudWatch Logs. func RecordToCloudWatch(group string, config client.ConfigProvider) RunRecorder { c := cloudwatchlogs.New(config) g := cloudwatch.NewGroup(group, c) return func() (io.Writer, error) { stream := uuid.New() w, err := g.Create(stream) if err != nil { return nil, err } url := fmt.Sprintf("https://console.aws.amazon.com/cloudwatch/home?region=%s#logEvent:group=%s;stream=%s", *c.Config.Region, group, stream) return &writerWithURL{w, url}, nil } }
func NewLogger(group string) *Group { c := cloudwatchlogs.New(defaults.DefaultConfig) return &Group{cloudwatch.NewGroup(group, c)} }