Implemented the logging viewer
This commit is contained in:
parent
37c901636c
commit
3257fe2f32
@ -16,6 +16,9 @@ func AddLoggingDevice(device Device.Device) {
|
||||
go func() {
|
||||
mutexDevices.Lock()
|
||||
devices.PushBack(newDevice)
|
||||
|
||||
// Let each device know what the project name is:
|
||||
newDevice.SetProjectName(projectName)
|
||||
mutexDevices.Unlock()
|
||||
}()
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ import (
|
||||
type Device interface {
|
||||
Log(logEntries []Meta.Entry)
|
||||
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
|
||||
|
||||
import (
|
||||
"github.com/SommerEngineering/Ocean/Log"
|
||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
"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
|
||||
//
|
||||
|
||||
// Define the query:
|
||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`).Limit(26)
|
||||
count := 26
|
||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`) // TODO: projectName!!!
|
||||
|
||||
// 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:
|
||||
if n, err := query.Count(); err == nil {
|
||||
|
@ -1,14 +1,30 @@
|
||||
package DeviceDatabase
|
||||
|
||||
import (
|
||||
"github.com/SommerEngineering/Ocean/Log"
|
||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"math"
|
||||
)
|
||||
|
||||
// Read the latest logging events from the database.
|
||||
func ReadLatest() (events []LogDBEntry) {
|
||||
func ReadLatest() (events []LogDBEntry, numPages int) {
|
||||
// Define the query:
|
||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`).Limit(26)
|
||||
count := 26
|
||||
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`) // TODO: projectName!!!
|
||||
|
||||
// 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:
|
||||
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 (
|
||||
// This is the name for logging event from this package:
|
||||
senderName LM.Sender = `System::Logger::Database`
|
||||
mutexCacheFull sync.Mutex = sync.Mutex{}
|
||||
mutexCacheSenderNames sync.RWMutex = sync.RWMutex{}
|
||||
mutexCacheMessageNames sync.RWMutex = sync.RWMutex{}
|
||||
cache chan LogDBEntry = nil
|
||||
cacheSizeNumberOfEvents int = 50
|
||||
cacheSizeTime2FlushSeconds int = 6
|
||||
nameCachesRefreshTimeSeconds int = 300
|
||||
cacheSenderNames []Scheme.Sender = nil
|
||||
cacheMessageNames []Scheme.MessageNames = nil
|
||||
logDB *mgo.Database = nil
|
||||
logDBSession *mgo.Session = nil
|
||||
logDBCollection *mgo.Collection = nil
|
||||
senderName LM.Sender = `System::Logger::Database` // This is the name for logging event from this package
|
||||
mutexCacheFull sync.Mutex = sync.Mutex{} // Mutex for the cache full event
|
||||
mutexCacheSenderNames sync.RWMutex = sync.RWMutex{} // Read/write mutex for the sender names
|
||||
mutexCacheMessageNames sync.RWMutex = sync.RWMutex{} // Read/write mutex for the messages names
|
||||
cache chan LogDBEntry = nil // The cache
|
||||
cacheSizeNumberOfEvents int = 50 // How many events are cached?
|
||||
cacheSizeTime2FlushSeconds int = 6 // Wait how many seconds before forcing to write events?
|
||||
nameCachesRefreshTimeSeconds int = 300 // Wait how many seconds until we reload the sender and message names?
|
||||
cacheSenderNames []Scheme.Sender = nil // Cache for the sender names
|
||||
cacheMessageNames []Scheme.MessageNames = nil // Cache for the message names
|
||||
logDB *mgo.Database = nil // The logging database
|
||||
logDBSession *mgo.Session = nil // The logging database session
|
||||
logDBCollection *mgo.Collection = nil // The logging collection
|
||||
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?
|
||||
if countParameters < 9 {
|
||||
// Initial view => first page (latest logs)
|
||||
data.Events = readLatest()
|
||||
data.Events, lastPageNumber = readLatest()
|
||||
data.SetLiveView = true
|
||||
data.CurrentPage = `1`
|
||||
data.LastPage = fmt.Sprintf("%d", lastPageNumber)
|
||||
@ -66,7 +66,7 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
||||
currentLiveView := request.FormValue(`LiveView`)
|
||||
|
||||
// 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` {
|
||||
data.SetLiveView = true
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
// 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:
|
||||
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)
|
||||
|
||||
// Array with all events, prepared for the website:
|
||||
@ -32,5 +32,6 @@ func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMes
|
||||
}
|
||||
}
|
||||
|
||||
numPages = totalNumberPages
|
||||
return
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
// 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
|
||||
eventsFromDB := DeviceDatabase.ReadLatest()
|
||||
eventsFromDB, totalNumberPages := DeviceDatabase.ReadLatest()
|
||||
count := len(eventsFromDB)
|
||||
|
||||
// Array for the log events, prepared for the website:
|
||||
@ -31,5 +31,6 @@ func readLatest() (events []Scheme.LogEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
numPages = totalNumberPages
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user