@@ -10,7 +10,7 @@ import Cardano.Tracer.Environment
10
10
import Cardano.Tracer.Handlers.Logs.Utils (createOrUpdateEmptyLog , getTimeStampFromLog ,
11
11
isItLog )
12
12
import Cardano.Tracer.MetaTrace
13
- import Cardano.Tracer.Types (HandleRegistry , NodeName )
13
+ import Cardano.Tracer.Types (HandleRegistry , HandleRegistryKey , NodeName )
14
14
import Cardano.Tracer.Utils (showProblemIfAny , readRegistry )
15
15
16
16
import Control.Concurrent.Async (forConcurrently_ )
@@ -77,7 +77,7 @@ checkRootDir
77
77
-> RotationParams
78
78
-> LoggingParams
79
79
-> IO ()
80
- checkRootDir currentLogLock registry rotParams loggingParams@ LoggingParams {logRoot, logFormat } = do
80
+ checkRootDir currentLogLock registry rotParams loggingParams@ LoggingParams {logRoot} = do
81
81
logRootAbs <- makeAbsolute logRoot
82
82
whenM (doesDirectoryExist logRootAbs) do
83
83
logsSubDirs <- listDirectories logRootAbs
@@ -92,27 +92,25 @@ checkRootDir currentLogLock registry rotParams loggingParams@LoggingParams{logRo
92
92
let nodeName :: NodeName
93
93
nodeName = Text. pack (takeFileName logSubDir)
94
94
95
- for_ @ Maybe ( Map. lookup (nodeName, loggingParams) handles) \ (handle, filePath) -> let
96
- nodeName' :: NodeName
97
- nodeName' = Text. pack filePath
98
- in
99
- checkLogs currentLogLock handle nodeName' loggingParams registry rotParams logFormat (logRootAbs </> logSubDir)
95
+ key :: HandleRegistryKey
96
+ key = (nodeName, loggingParams)
97
+
98
+ for_ @ Maybe ( Map. lookup key handles) \ (handle, _filePath) ->
99
+ checkLogs currentLogLock handle key registry rotParams (logRootAbs </> logSubDir)
100
100
101
101
-- | We check the log files:
102
102
-- 1. If there are too big log files.
103
103
-- 2. If there are too old log files.
104
104
checkLogs
105
105
:: Lock
106
106
-> Handle
107
- -> NodeName
108
- -> LoggingParams
107
+ -> HandleRegistryKey
109
108
-> HandleRegistry
110
109
-> RotationParams
111
- -> LogFormat
112
110
-> FilePath
113
111
-> IO ()
114
- checkLogs currentLogLock handle nodeName loggingParams registry
115
- RotationParams {rpLogLimitBytes, rpMaxAgeMinutes, rpKeepFilesNum} format subDirForLogs = do
112
+ checkLogs currentLogLock handle key @ (_, LoggingParams {logFormat = format}) registry
113
+ RotationParams {rpLogLimitBytes, rpMaxAgeMinutes, rpKeepFilesNum} subDirForLogs = do
116
114
117
115
logs <- map (subDirForLogs </> ) . filter (isItLog format) <$> listFiles subDirForLogs
118
116
unless (null logs) do
@@ -122,23 +120,21 @@ checkLogs currentLogLock handle nodeName loggingParams registry
122
120
-- Usage of partial function 'last' is safe here (we already checked the list isn't empty).
123
121
-- Only previous logs should be checked if they are outdated.
124
122
allOtherLogs = dropEnd 1 fromOldestToNewest
125
- checkIfCurrentLogIsFull currentLogLock handle nodeName loggingParams registry format rpLogLimitBytes subDirForLogs
123
+ checkIfCurrentLogIsFull currentLogLock handle key registry rpLogLimitBytes subDirForLogs
126
124
checkIfThereAreOldLogs allOtherLogs rpMaxAgeMinutes rpKeepFilesNum
127
125
128
126
-- | If the current log file is full (it's size is too big), the new log will be created.
129
127
checkIfCurrentLogIsFull
130
128
:: Lock
131
129
-> Handle
132
- -> NodeName
133
- -> LoggingParams
130
+ -> HandleRegistryKey
134
131
-> HandleRegistry
135
- -> LogFormat
136
132
-> Word64
137
133
-> FilePath
138
134
-> IO ()
139
- checkIfCurrentLogIsFull currentLogLock handle nodeName loggingParams registry format maxSizeInBytes subDirForLogs =
135
+ checkIfCurrentLogIsFull currentLogLock handle key registry maxSizeInBytes subDirForLogs =
140
136
whenM logIsFull do
141
- createOrUpdateEmptyLog currentLogLock nodeName loggingParams registry subDirForLogs format
137
+ createOrUpdateEmptyLog currentLogLock key registry subDirForLogs
142
138
143
139
where
144
140
logIsFull :: IO Bool
0 commit comments