Implemented the logging viewer
This commit is contained in:
parent
37c901636c
commit
3257fe2f32
@ -16,6 +16,9 @@ func AddLoggingDevice(device Device.Device) {
|
|||||||
go func() {
|
go func() {
|
||||||
mutexDevices.Lock()
|
mutexDevices.Lock()
|
||||||
devices.PushBack(newDevice)
|
devices.PushBack(newDevice)
|
||||||
|
|
||||||
|
// Let each device know what the project name is:
|
||||||
|
newDevice.SetProjectName(projectName)
|
||||||
mutexDevices.Unlock()
|
mutexDevices.Unlock()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,5 @@ import (
|
|||||||
type Device interface {
|
type Device interface {
|
||||||
Log(logEntries []Meta.Entry)
|
Log(logEntries []Meta.Entry)
|
||||||
Flush()
|
Flush()
|
||||||
|
SetProjectName(projectName string)
|
||||||
}
|
}
|
||||||
|
6
Log/DeviceConsole/SetProjectName.go
Normal file
6
Log/DeviceConsole/SetProjectName.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package DeviceConsole
|
||||||
|
|
||||||
|
// Set the project name. This function is not necessary for the console logger.
|
||||||
|
func (dev Console) SetProjectName(projectName string) {
|
||||||
|
|
||||||
|
}
|
@ -1,18 +1,34 @@
|
|||||||
package DeviceDatabase
|
package DeviceDatabase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []LogDBEntry) {
|
func ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []LogDBEntry, numPages int) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO => Is currently a stub
|
// TODO => Is currently a stub
|
||||||
//
|
//
|
||||||
|
|
||||||
// Define the query:
|
// Define the query:
|
||||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`).Limit(26)
|
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`) // TODO: projectName!!!
|
||||||
count := 26
|
|
||||||
|
// How many record we have all over?
|
||||||
|
numRecords := loggingViewerPageSize
|
||||||
|
numPages = 1
|
||||||
|
if number, err := query.Count(); err != nil {
|
||||||
|
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityNone, LM.ImpactNone, LM.MessageNameDATABASE, `It was not possible to find the total number of records for the custom logging reader.`, err.Error())
|
||||||
|
} else {
|
||||||
|
numRecords = number
|
||||||
|
numPages = int(math.Ceil(float64(numRecords) / float64(loggingViewerPageSize)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set now the page's record limit:
|
||||||
|
query = query.Limit(loggingViewerPageSize)
|
||||||
|
count := loggingViewerPageSize
|
||||||
|
|
||||||
// Execute the query and count the results:
|
// Execute the query and count the results:
|
||||||
if n, err := query.Count(); err == nil {
|
if n, err := query.Count(); err == nil {
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
package DeviceDatabase
|
package DeviceDatabase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Read the latest logging events from the database.
|
// Read the latest logging events from the database.
|
||||||
func ReadLatest() (events []LogDBEntry) {
|
func ReadLatest() (events []LogDBEntry, numPages int) {
|
||||||
// Define the query:
|
// Define the query:
|
||||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`).Limit(26)
|
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`) // TODO: projectName!!!
|
||||||
count := 26
|
|
||||||
|
// How many record we have all over?
|
||||||
|
numRecords := loggingViewerPageSize
|
||||||
|
numPages = 1
|
||||||
|
if number, err := query.Count(); err != nil {
|
||||||
|
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityNone, LM.ImpactNone, LM.MessageNameDATABASE, `It was not possible to find the total number of records for the latest logging reader.`, err.Error())
|
||||||
|
} else {
|
||||||
|
numRecords = number
|
||||||
|
numPages = int(math.Ceil(float64(numRecords) / float64(loggingViewerPageSize)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set now the page's record limit:
|
||||||
|
query = query.Limit(loggingViewerPageSize)
|
||||||
|
count := loggingViewerPageSize
|
||||||
|
|
||||||
// Execute the query and count the results:
|
// Execute the query and count the results:
|
||||||
if n, err := query.Count(); err == nil {
|
if n, err := query.Count(); err == nil {
|
||||||
|
6
Log/DeviceDatabase/SetProjectName.go
Normal file
6
Log/DeviceDatabase/SetProjectName.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package DeviceDatabase
|
||||||
|
|
||||||
|
// Set the project name.
|
||||||
|
func (dev Database) SetProjectName(name string) {
|
||||||
|
projectName = name
|
||||||
|
}
|
@ -8,18 +8,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// This is the name for logging event from this package:
|
senderName LM.Sender = `System::Logger::Database` // This is the name for logging event from this package
|
||||||
senderName LM.Sender = `System::Logger::Database`
|
mutexCacheFull sync.Mutex = sync.Mutex{} // Mutex for the cache full event
|
||||||
mutexCacheFull sync.Mutex = sync.Mutex{}
|
mutexCacheSenderNames sync.RWMutex = sync.RWMutex{} // Read/write mutex for the sender names
|
||||||
mutexCacheSenderNames sync.RWMutex = sync.RWMutex{}
|
mutexCacheMessageNames sync.RWMutex = sync.RWMutex{} // Read/write mutex for the messages names
|
||||||
mutexCacheMessageNames sync.RWMutex = sync.RWMutex{}
|
cache chan LogDBEntry = nil // The cache
|
||||||
cache chan LogDBEntry = nil
|
cacheSizeNumberOfEvents int = 50 // How many events are cached?
|
||||||
cacheSizeNumberOfEvents int = 50
|
cacheSizeTime2FlushSeconds int = 6 // Wait how many seconds before forcing to write events?
|
||||||
cacheSizeTime2FlushSeconds int = 6
|
nameCachesRefreshTimeSeconds int = 300 // Wait how many seconds until we reload the sender and message names?
|
||||||
nameCachesRefreshTimeSeconds int = 300
|
cacheSenderNames []Scheme.Sender = nil // Cache for the sender names
|
||||||
cacheSenderNames []Scheme.Sender = nil
|
cacheMessageNames []Scheme.MessageNames = nil // Cache for the message names
|
||||||
cacheMessageNames []Scheme.MessageNames = nil
|
logDB *mgo.Database = nil // The logging database
|
||||||
logDB *mgo.Database = nil
|
logDBSession *mgo.Session = nil // The logging database session
|
||||||
logDBSession *mgo.Session = nil
|
logDBCollection *mgo.Collection = nil // The logging collection
|
||||||
logDBCollection *mgo.Collection = nil
|
loggingViewerPageSize int = 26 // How many records per page for the logging web viewer?
|
||||||
|
projectName string = `not set` // The project name for the logging
|
||||||
|
isProjectNameSet bool = false // Status about the project name
|
||||||
)
|
)
|
||||||
|
@ -42,7 +42,7 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
|||||||
// To less parameters?
|
// To less parameters?
|
||||||
if countParameters < 9 {
|
if countParameters < 9 {
|
||||||
// Initial view => first page (latest logs)
|
// Initial view => first page (latest logs)
|
||||||
data.Events = readLatest()
|
data.Events, lastPageNumber = readLatest()
|
||||||
data.SetLiveView = true
|
data.SetLiveView = true
|
||||||
data.CurrentPage = `1`
|
data.CurrentPage = `1`
|
||||||
data.LastPage = fmt.Sprintf("%d", lastPageNumber)
|
data.LastPage = fmt.Sprintf("%d", lastPageNumber)
|
||||||
@ -66,7 +66,7 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
|||||||
currentLiveView := request.FormValue(`LiveView`)
|
currentLiveView := request.FormValue(`LiveView`)
|
||||||
|
|
||||||
// Store the events for the template:
|
// Store the events for the template:
|
||||||
data.Events = readCustom(currentTimeRange, currentLevel, currentCategory, currentImpact, currentSeverity, currentMessageName, currentSender, currentPage)
|
data.Events, lastPageNumber = readCustom(currentTimeRange, currentLevel, currentCategory, currentImpact, currentSeverity, currentMessageName, currentSender, currentPage)
|
||||||
|
|
||||||
if strings.ToLower(currentLiveView) == `true` {
|
if strings.ToLower(currentLiveView) == `true` {
|
||||||
data.SetLiveView = true
|
data.SetLiveView = true
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Read a custom event range from the database.
|
// Read a custom event range from the database.
|
||||||
func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []Scheme.LogEvent) {
|
func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []Scheme.LogEvent, numPages int) {
|
||||||
|
|
||||||
// Get the custom events:
|
// Get the custom events:
|
||||||
eventsFromDB := DeviceDatabase.ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage)
|
eventsFromDB, totalNumberPages := DeviceDatabase.ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage)
|
||||||
count := len(eventsFromDB)
|
count := len(eventsFromDB)
|
||||||
|
|
||||||
// Array with all events, prepared for the website:
|
// Array with all events, prepared for the website:
|
||||||
@ -32,5 +32,6 @@ func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numPages = totalNumberPages
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Read the latest log events from the database
|
// Read the latest log events from the database
|
||||||
func readLatest() (events []Scheme.LogEvent) {
|
func readLatest() (events []Scheme.LogEvent, numPages int) {
|
||||||
// Get the latest events from the database
|
// Get the latest events from the database
|
||||||
eventsFromDB := DeviceDatabase.ReadLatest()
|
eventsFromDB, totalNumberPages := DeviceDatabase.ReadLatest()
|
||||||
count := len(eventsFromDB)
|
count := len(eventsFromDB)
|
||||||
|
|
||||||
// Array for the log events, prepared for the website:
|
// Array for the log events, prepared for the website:
|
||||||
@ -31,5 +31,6 @@ func readLatest() (events []Scheme.LogEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numPages = totalNumberPages
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user