Ocean/Log/Flush.go
Thorsten Sommer f33f7b5c29 Refactoring, Bugfix & Updates
+ Refactored all imports
+ Fixed a bug for the logging regarding removing \n \t \r
+ Updated to current MGO release
+ Changed the name of ICCC
2014-10-19 19:19:11 +02:00

36 lines
972 B
Go

package Log
import (
"github.com/SommerEngineering/Ocean/Log/Device"
"time"
)
/*
Please do not call this function your self! This function allows Ocean to flush the logging at the shutting down case.
*/
func Flush() {
mutexChannel.Lock()
channelReady = false
close(entriesBuffer)
mutexChannel.Unlock()
// This is a bad design, but the scheduler need some time to write the last messages.
time.Sleep(15 * time.Second)
mutexDeviceDelays.Lock()
dataArray := logEntryListToArray(deviceDelayBuffer)
deviceDelayBuffer.Init()
mutexDeviceDelays.Unlock()
mutexDevices.RLock()
for entry := devices.Front(); entry != nil; entry = entry.Next() {
dev := entry.Value.(Device.Device)
dev.Log(dataArray) // Want to wait to complete, therefore no new thread here
go dev.Flush()
}
mutexDevices.RUnlock()
// This is a bad design, but the devices need (may) some time to write the last messages:
time.Sleep(15 * time.Second)
}