Implemented the logging viewer

This commit is contained in:
Thorsten Sommer committed 2015-06-23 07:49:59 +02:00
1 parent 37c901636c
commit 3257fe2f32
10 files changed
+78 -26

No files matched your search

+19 -3
View File
@@ -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 {
+19 -3
View File
@@ -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
View File
@@ -0,0 +1,6 @@
package DeviceDatabase
// Set the project name.
func (dev Database) SetProjectName(name string) {
projectName = name
}
+16 -14
View File
@@ -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
)