github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/events/sinks/log/log_sink.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package logsink 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "github.com/golang/glog" 22 "k8s.io/heapster/events/core" 23 ) 24 25 type LogSink struct { 26 } 27 28 func (this *LogSink) Name() string { 29 return "LogSink" 30 } 31 32 func (this *LogSink) Stop() { 33 // Do nothing. 34 } 35 36 func batchToString(batch *core.EventBatch) string { 37 var buffer bytes.Buffer 38 buffer.WriteString(fmt.Sprintf("EventBatch Timestamp: %s\n", batch.Timestamp)) 39 for _, event := range batch.Events { 40 buffer.WriteString(fmt.Sprintf(" %s (cnt:%d): %s\n", event.LastTimestamp, event.Count, event.Message)) 41 } 42 return buffer.String() 43 } 44 45 func (this *LogSink) ExportEvents(batch *core.EventBatch) { 46 glog.Info(batchToString(batch)) 47 } 48 49 func CreateLogSink() (*LogSink, error) { 50 return &LogSink{}, nil 51 }