add container log struct to models, collectors

This commit is contained in:
Bradley Cicenas
2017-07-04 12:32:25 +00:00
parent 65399a37e5
commit 79a3f361a7
5 changed files with 40 additions and 14 deletions

View File

@@ -1,17 +1,20 @@
package expanded
import (
"time"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
type LogLines struct {
ts []string
ts []time.Time
data []string
}
func NewLogLines(max int) *LogLines {
ll := &LogLines{
ts: make([]string, max),
ts: make([]time.Time, max),
data: make([]string, max),
}
return ll
@@ -31,14 +34,14 @@ func (ll *LogLines) getLines(start, end int) []string {
return ll.data[start:end]
}
func (ll *LogLines) add(s string) {
func (ll *LogLines) add(l models.Log) {
if len(ll.data) == cap(ll.data) {
ll.data = append(ll.data[:0], ll.data[1:]...)
ll.ts = append(ll.ts[:0], ll.ts[1:]...)
}
ll.ts = append(ll.ts, "timestamp")
ll.data = append(ll.data, s)
log.Debugf("recorded log line: %v", s)
ll.ts = append(ll.ts, l.Timestamp)
ll.data = append(ll.data, l.Message)
log.Debugf("recorded log line: %v", l)
}
type Logs struct {
@@ -46,7 +49,7 @@ type Logs struct {
lines *LogLines
}
func NewLogs(stream chan string) *Logs {
func NewLogs(stream chan models.Log) *Logs {
p := ui.NewList()
p.Y = ui.TermHeight() / 2
p.X = 0