@@ -6,17 +6,16 @@ module Cardano.Tracer.Handlers.Logs.Rotator
66 ) where
77
88import Cardano.Tracer.Configuration
9- import Cardano.Tracer.Environment ( TracerEnv ( .. ), forever'tilShutdown )
9+ import Cardano.Tracer.Environment
1010import Cardano.Tracer.Handlers.Logs.Utils (createOrUpdateEmptyLog , getTimeStampFromLog ,
1111 isItLog )
1212import Cardano.Tracer.MetaTrace
1313import Cardano.Tracer.Types (HandleRegistry , HandleRegistryKey , NodeName )
1414import Cardano.Tracer.Utils (showProblemIfAny , readRegistry )
1515
1616import Control.Concurrent.Async (forConcurrently_ )
17- import Control.Concurrent.Chan.Unagi (dupChan )
1817import Control.Concurrent.Extra (Lock )
19- import Control.Monad (forM_ , unless , when )
18+ import Control.Monad (forM_ , forever , unless , when )
2019import Control.Monad.Extra (whenJust , whenM )
2120import Data.Foldable (for_ )
2221import Data.List (nub , sort )
@@ -34,40 +33,38 @@ import System.Time.Extra (sleep)
3433
3534-- | Runs rotation mechanism for the log files.
3635runLogsRotator :: TracerEnv -> IO ()
37- runLogsRotator tracerEnv@ TracerEnv { teConfig = TracerConfig {rotation}, teTracer } = do
38- whenJust rotation \ rot -> do
36+ runLogsRotator TracerEnv
37+ { teConfig = TracerConfig {rotation, verbosity, logging}
38+ , teCurrentLogLock
39+ , teTracer
40+ , teRegistry
41+ } = do
42+ whenJust rotation \ rotParams -> do
3943 traceWith teTracer TracerStartedLogRotator
40- launchRotator tracerEnv rot
41-
42- launchRotator
43- :: TracerEnv
44- -> RotationParams
45- -> IO ()
46- launchRotator tracerEnv rot@ RotationParams {rpFrequencySecs} = do
47- whenNonEmpty loggingParamsForFiles do
48- outChan <- dupChan teInChan
49- forever'tilShutdown outChan do
50- showProblemIfAny verbosity do
51- forM_ loggingParamsForFiles \ loggingParam -> do
52- checkRootDir teCurrentLogLock teRegistry rot loggingParam
53- sleep (fromIntegral rpFrequencySecs)
54- where
55- whenNonEmpty :: Applicative f => [a ] -> f () -> f ()
56- whenNonEmpty = unless . null
57-
58- TracerEnv
59- { teConfig = TracerConfig {verbosity, logging}
60- , teCurrentLogLock
61- , teRegistry
62- , teInChan
63- } = tracerEnv
64-
44+ launchRotator loggingParamsForFiles rotParams verbosity teRegistry teCurrentLogLock
45+ where
6546 loggingParamsForFiles :: [LoggingParams ]
6647 loggingParamsForFiles = nub (NE. filter filesOnly logging)
6748
6849 filesOnly :: LoggingParams -> Bool
6950 filesOnly LoggingParams {logMode} = logMode == FileMode
7051
52+ launchRotator
53+ :: [LoggingParams ]
54+ -> RotationParams
55+ -> Maybe Verbosity
56+ -> HandleRegistry
57+ -> Lock
58+ -> IO ()
59+ launchRotator [] _ _ _ _ = return ()
60+ launchRotator loggingParamsForFiles
61+ rotParams@ RotationParams {rpFrequencySecs} verb registry currentLogLock =
62+ forever do
63+ showProblemIfAny verb do
64+ forM_ loggingParamsForFiles \ loggingParam -> do
65+ checkRootDir currentLogLock registry rotParams loggingParam
66+ sleep $ fromIntegral rpFrequencySecs
67+
7168-- | All the logs with 'TraceObject's received from particular node
7269-- will be stored in a separate subdirectory in the root directory.
7370--
0 commit comments