From e28999e15fd85f668ed140fd48aedc03e57f62f2 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Fri, 7 Nov 2014 13:30:33 +0100 Subject: [PATCH] Logging expire *** Not done yet *** + Added configurations for the expire logging function + Added the expire logging function --- ConfigurationDB/CheckConfiguration.go | 2 ++ Log/DeviceDatabase/InitDB.go | 23 +++++++++++++++++++++++ Main.go | 1 - 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ConfigurationDB/CheckConfiguration.go b/ConfigurationDB/CheckConfiguration.go index a102c4f..a2e4bc1 100644 --- a/ConfigurationDB/CheckConfiguration.go +++ b/ConfigurationDB/CheckConfiguration.go @@ -30,6 +30,8 @@ func checkConfiguration() { CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBPassword`, `please replace this with a good password`) CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeNumberOfEvents`, `50`) CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeTime2FlushSeconds`, `6`) + CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpire`, `True`) + CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpireAfterDays`, `365`) CheckSingleConfigurationPresentsAndAddIfMissing(`LogBufferSize`, `500`) CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayNumberEvents`, `600`) CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayTime2FlushSeconds`, `5`) diff --git a/Log/DeviceDatabase/InitDB.go b/Log/DeviceDatabase/InitDB.go index f282100..220b2bc 100644 --- a/Log/DeviceDatabase/InitDB.go +++ b/Log/DeviceDatabase/InitDB.go @@ -1,10 +1,14 @@ package DeviceDatabase import ( + "fmt" "github.com/SommerEngineering/Ocean/ConfigurationDB" "github.com/SommerEngineering/Ocean/Log" LM "github.com/SommerEngineering/Ocean/Log/Meta" "gopkg.in/mgo.v2" + "strconv" + "strings" + "time" ) func initDatabase() { @@ -16,6 +20,18 @@ func initDatabase() { databaseDB := ConfigurationDB.Read(`LogDBDatabase`) databaseUsername := ConfigurationDB.Read(`LogDBUsername`) 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: if newSession, errDial := mgo.Dial(databaseHost); errDial != nil { @@ -44,6 +60,13 @@ func initDatabase() { indexTimeUTC.Key = []string{`TimeUTC`} 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.Key = []string{`Project`} logDBCollection.EnsureIndex(indexProject) diff --git a/Main.go b/Main.go index c0daf8b..968dc79 100644 --- a/Main.go +++ b/Main.go @@ -7,7 +7,6 @@ import ( ) func main() { - Log.LogShort(senderName, LM.CategoryAPP, LM.LevelINFO, LM.MessageNameSTARTUP, `VRStudiePT is starting.`) System.InitHandlers() System.StartAndBlockForever()