Ocean/Log/Web/ReadLatest.go

37 lines
972 B
Go
Raw Permalink Normal View History

package Web
import (
"fmt"
2015-06-22 12:08:29 +00:00
"github.com/SommerEngineering/Ocean/Admin/Scheme"
"github.com/SommerEngineering/Ocean/Log/DeviceDatabase"
"strings"
)
2015-06-17 15:44:52 +00:00
// Read the latest log events from the database
2015-06-23 05:49:59 +00:00
func readLatest() (events []Scheme.LogEvent, numPages int) {
2015-06-17 15:44:52 +00:00
// Get the latest events from the database
2015-06-23 05:49:59 +00:00
eventsFromDB, totalNumberPages := DeviceDatabase.ReadLatest()
count := len(eventsFromDB)
2015-06-17 15:44:52 +00:00
// Array for the log events, prepared for the website:
events = make([]Scheme.LogEvent, count)
2015-06-17 15:44:52 +00:00
// Copy each event to the right format for the website:
for n := 0; n < count; n++ {
eventFromDB := eventsFromDB[n]
events[n] = Scheme.LogEvent{}
events[n].LogLine = eventFromDB.Format()
events[n].LogLevel = fmt.Sprintf("log%s", strings.ToLower(eventFromDB.Level[2:]))
2015-06-17 15:44:52 +00:00
// Vary the color of each line:
if n%2 == 0 {
events[n].AB = Scheme.B
} else {
events[n].AB = Scheme.A
}
}
2015-06-23 05:49:59 +00:00
numPages = totalNumberPages
return
}