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(`LogDBCacheSizeNumberOfEvents`, `50`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBCacheSizeTime2FlushSeconds`, `6`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpire`, `True`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDBEventsExpireAfterDays`, `365`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogBufferSize`, `500`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayNumberEvents`, `600`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`LogDeviceDelayTime2FlushSeconds`, `5`)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user