improve logging: line buffering, time stamps

contributes to #60
This commit is contained in:
Trolli Schmittlauch 2020-09-16 01:54:50 +02:00
parent bb17b136d6
commit a2f268d374

View file

@ -100,6 +100,7 @@ instance DHT d => Service PostService d where
statsQueue' <- newTQueueIO statsQueue' <- newTQueueIO
loadStats' <- newTVarIO emptyStats loadStats' <- newTVarIO emptyStats
loggingFile <- openFile (confLogfilePath conf) WriteMode loggingFile <- openFile (confLogfilePath conf) WriteMode
hSetBuffering loggingFile LineBuffering
let let
thisService = PostService thisService = PostService
{ serviceConf = conf { serviceConf = conf
@ -121,7 +122,7 @@ instance DHT d => Service PostService d where
-- log a start message, this also truncates existing files -- log a start message, this also truncates existing files
TxtI.hPutStrLn loggingFile $ Txt.unlines TxtI.hPutStrLn loggingFile $ Txt.unlines
[ "# Starting mock relay implementation" [ "# Starting mock relay implementation"
, "#relay receive rate ;relay delivery rate ;instance publish rate ;instance fetch rate ;total subscriptions" , "#time stamp ; relay receive rate ;relay delivery rate ;instance publish rate ;instance fetch rate ;total subscriptions"
] ]
-- Run 'concurrently_' from another thread to be able to return the -- Run 'concurrently_' from another thread to be able to return the
-- 'PostService'. -- 'PostService'.
@ -841,7 +842,8 @@ evaluateStatsThread serv statsAcc = getPOSIXTime >>= loop
-- later: current (reported) load, target load -- later: current (reported) load, target load
subscriberSum <- sumSubscribers subscriberSum <- sumSubscribers
TxtI.hPutStrLn (logFileHandle serv) $ TxtI.hPutStrLn (logFileHandle serv) $
format (fixed 20 % ";" % fixed 20 % ";" % fixed 20 % ";" % fixed 20 % ";" % int ) format (fixed 9 % ";" % fixed 20 % ";" % fixed 20 % ";" % fixed 20 % ";" % fixed 20 % ";" % int )
(realToFrac now :: Double)
(sum . relayReceiveRates $ rateStats) (sum . relayReceiveRates $ rateStats)
(sum . relayDeliveryRates $ rateStats) (sum . relayDeliveryRates $ rateStats)
(postPublishRate rateStats) (postPublishRate rateStats)