2015-02-05 20:30:32 +00:00
|
|
|
package Web
|
|
|
|
|
|
|
|
import (
|
2015-02-26 15:37:36 +00:00
|
|
|
"fmt"
|
2015-02-06 13:12:45 +00:00
|
|
|
"github.com/SommerEngineering/Ocean/Log/DeviceDatabase"
|
2015-02-05 20:30:32 +00:00
|
|
|
"github.com/SommerEngineering/Ocean/Log/Web/Scheme"
|
2015-02-26 15:37:36 +00:00
|
|
|
"strings"
|
2015-02-05 20:30:32 +00:00
|
|
|
)
|
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Read the latest log events from the database
|
2015-02-05 20:30:32 +00:00
|
|
|
func readLatest() (events []Scheme.LogEvent) {
|
2015-06-17 15:44:52 +00:00
|
|
|
// Get the latest events from the database
|
2015-02-06 13:12:45 +00:00
|
|
|
eventsFromDB := DeviceDatabase.ReadLatest()
|
|
|
|
count := len(eventsFromDB)
|
2015-06-17 15:44:52 +00:00
|
|
|
|
|
|
|
// Array for the log events, prepared for the website:
|
2015-02-06 13:12:45 +00:00
|
|
|
events = make([]Scheme.LogEvent, count)
|
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Copy each event to the right format for the website:
|
2015-02-06 13:12:45 +00:00
|
|
|
for n := 0; n < count; n++ {
|
|
|
|
eventFromDB := eventsFromDB[n]
|
|
|
|
events[n] = Scheme.LogEvent{}
|
2015-02-25 19:53:50 +00:00
|
|
|
events[n].LogLine = eventFromDB.Format()
|
2015-02-26 15:37:36 +00:00
|
|
|
events[n].LogLevel = fmt.Sprintf("log%s", strings.ToLower(eventFromDB.Level[2:]))
|
2015-02-06 13:12:45 +00:00
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Vary the color of each line:
|
2015-02-06 13:12:45 +00:00
|
|
|
if n%2 == 0 {
|
|
|
|
events[n].AB = Scheme.B
|
|
|
|
} else {
|
|
|
|
events[n].AB = Scheme.A
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 20:30:32 +00:00
|
|
|
return
|
|
|
|
}
|