Skip to content

Commit

Permalink
Flush logs only in log write thread
Browse files Browse the repository at this point in the history
Also add some traces to see whether this is actually executed.
  • Loading branch information
ch1bo committed Mar 17, 2023
1 parent bbe90bf commit 7e53b56
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hydra-node/src/Hydra/Logging.hs
Expand Up @@ -49,6 +49,7 @@ import Data.Aeson (pairs, (.=))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as Text
import Debug.Trace (traceIO)
import Test.QuickCheck.Instances.Text ()
import Test.QuickCheck.Instances.Time ()

Expand Down Expand Up @@ -105,7 +106,7 @@ withTracerOutputTo ::
withTracerOutputTo hdl namespace action = do
msgQueue <- newTBQueueIO @_ @(Envelope msg) defaultQueueSize
withAsync (writeLogs msgQueue `finally` flushLogs msgQueue) $ \_ ->
action (tracer msgQueue) `finally` flushLogs msgQueue
action (tracer msgQueue)
where
tracer queue =
Tracer $
Expand All @@ -117,9 +118,11 @@ withTracerOutputTo hdl namespace action = do
hFlush hdl

flushLogs queue = liftIO $ do
traceIO "flushLogs start"
entries <- atomically $ flushTBQueue queue
forM_ entries (write . Aeson.encode)
hFlush hdl
traceIO "flushLogs end"

write bs = LBS.hPut hdl (bs <> "\n")

Expand Down

0 comments on commit 7e53b56

Please sign in to comment.