Logging expire
*** Not done yet *** + Added configurations for the expire logging function + Added the expire logging function
This commit is contained in:
parent
3348e552cc
commit
e28999e15f
@ -30,6 +30,8 @@ func checkConfiguration() {
|
|||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBPassword`, `please replace this with a good password`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBPassword`, `please replace this with a good password`)
|
||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeNumberOfEvents`, `50`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeNumberOfEvents`, `50`)
|
||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeTime2FlushSeconds`, `6`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeTime2FlushSeconds`, `6`)
|
||||||
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpire`, `True`)
|
||||||
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpireAfterDays`, `365`)
|
||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogBufferSize`, `500`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogBufferSize`, `500`)
|
||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayNumberEvents`, `600`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayNumberEvents`, `600`)
|
||||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayTime2FlushSeconds`, `5`)
|
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayTime2FlushSeconds`, `5`)
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package DeviceDatabase
|
package DeviceDatabase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/SommerEngineering/Ocean/ConfigurationDB"
|
"github.com/SommerEngineering/Ocean/ConfigurationDB"
|
||||||
"github.com/SommerEngineering/Ocean/Log"
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
"gopkg.in/mgo.v2"
|
"gopkg.in/mgo.v2"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initDatabase() {
|
func initDatabase() {
|
||||||
@ -16,6 +20,18 @@ func initDatabase() {
|
|||||||
databaseDB := ConfigurationDB.Read(`LogDBDatabase`)
|
databaseDB := ConfigurationDB.Read(`LogDBDatabase`)
|
||||||
databaseUsername := ConfigurationDB.Read(`LogDBUsername`)
|
databaseUsername := ConfigurationDB.Read(`LogDBUsername`)
|
||||||
databasePassword := ConfigurationDB.Read(`LogDBPassword`)
|
databasePassword := ConfigurationDB.Read(`LogDBPassword`)
|
||||||
|
expire := strings.ToLower(ConfigurationDB.Read(`LogDBEventsExpire`)) == `true`
|
||||||
|
expireAfterDays := 36500
|
||||||
|
|
||||||
|
if value, errValue := strconv.Atoi(ConfigurationDB.Read(`LogDBEventsExpireAfterDays`)); errValue != nil {
|
||||||
|
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityMiddle, LM.ImpactUnknown, LM.MessageNameCONFIGURATION, `It was not possible to read the configuration for the expire time of logging events. Log events will not expire any more.`, errValue.Error())
|
||||||
|
expire = false
|
||||||
|
} else {
|
||||||
|
if expire {
|
||||||
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameCONFIGURATION, fmt.Sprintf("All logging events are expire after %d days.", value))
|
||||||
|
expireAfterDays = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to MongoDB:
|
// Connect to MongoDB:
|
||||||
if newSession, errDial := mgo.Dial(databaseHost); errDial != nil {
|
if newSession, errDial := mgo.Dial(databaseHost); errDial != nil {
|
||||||
@ -44,6 +60,13 @@ func initDatabase() {
|
|||||||
indexTimeUTC.Key = []string{`TimeUTC`}
|
indexTimeUTC.Key = []string{`TimeUTC`}
|
||||||
logDBCollection.EnsureIndex(indexTimeUTC)
|
logDBCollection.EnsureIndex(indexTimeUTC)
|
||||||
|
|
||||||
|
if expire {
|
||||||
|
indexTTL := mgo.Index{}
|
||||||
|
indexTTL.Key = []string{`TimeUTC`}
|
||||||
|
indexTTL.ExpireAfter = time.Duration(expireAfterDays) * time.Hour * 24
|
||||||
|
logDBCollection.EnsureIndex(indexTTL)
|
||||||
|
}
|
||||||
|
|
||||||
indexProject := mgo.Index{}
|
indexProject := mgo.Index{}
|
||||||
indexProject.Key = []string{`Project`}
|
indexProject.Key = []string{`Project`}
|
||||||
logDBCollection.EnsureIndex(indexProject)
|
logDBCollection.EnsureIndex(indexProject)
|
||||||
|
1
Main.go
1
Main.go
@ -7,7 +7,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
Log.LogShort(senderName, LM.CategoryAPP, LM.LevelINFO, LM.MessageNameSTARTUP, `VRStudiePT is starting.`)
|
Log.LogShort(senderName, LM.CategoryAPP, LM.LevelINFO, LM.MessageNameSTARTUP, `VRStudiePT is starting.`)
|
||||||
System.InitHandlers()
|
System.InitHandlers()
|
||||||
System.StartAndBlockForever()
|
System.StartAndBlockForever()
|
||||||
|
Loading…
Reference in New Issue
Block a user