Skip to content

Commit 990dce3

Browse files
committed
Refactor LogProxy again, add late filter predicate
1 parent 9703a3c commit 990dce3

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

booster/tools/booster/Server.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import Kore.Log.BoosterAdaptor (
7373
ExeName (..),
7474
KoreLogType (..),
7575
LogAction (LogAction),
76-
LogProxyActionData (..),
7776
TimestampsSwitch (TimestampsDisable),
7877
defaultKoreLogOptions,
7978
koreSomeEntryLogAction,
@@ -160,12 +159,14 @@ main = do
160159
koreSomeEntryLogAction
161160
(renderStandardPretty (ExeName "") (TimeSpec 0 0) TimestampsDisable)
162161
(not . logAsJson)
162+
(const True)
163163
(LogAction $ \txt -> liftIO $ monadLogger defaultLoc "kore" logLevel $ toLogStr txt)
164164

165165
koreJsonLogAction =
166166
koreSomeEntryLogAction
167167
(renderJson (ExeName "") (TimeSpec 0 0) TimestampsDisable)
168168
logAsJson
169+
(const True)
169170
( LogAction $ \txt ->
170171
let bytes = Text.encodeUtf8 $ prefix txt <> "\n"
171172
in liftIO $ do
@@ -184,12 +185,7 @@ main = do
184185
, Log.timestampsSwitch = TimestampsDisable
185186
, Log.debugSolverOptions =
186187
Log.DebugSolverOptions . fmap (<> ".kore") $ smtOptions >>= (.transcript)
187-
, Log.logType =
188-
LogProxy $
189-
Log.LogProxyActionData
190-
{ messageFilter = const True
191-
, logActions = koreLogActions
192-
}
188+
, Log.logType = LogProxy (mconcat koreLogActions)
193189
, Log.logFormat = Log.Standard
194190
}
195191
srvSettings = serverSettings port "*"

dev-tools/kore-rpc-dev/Server.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import Kore.Log.BoosterAdaptor (
6565
ExeName (..),
6666
KoreLogType (..),
6767
LogAction (LogAction),
68-
LogProxyActionData (..),
6968
TimestampsSwitch (TimestampsDisable),
7069
defaultKoreLogOptions,
7170
koreSomeEntryLogAction,
@@ -183,12 +182,14 @@ main = do
183182
koreSomeEntryLogAction
184183
(renderStandardPretty (ExeName "") (TimeSpec 0 0) TimestampsDisable)
185184
(not . logAsJson)
185+
(const True)
186186
(LogAction $ \txt -> liftIO $ monadLogger defaultLoc "kore" logLevel $ toLogStr txt)
187187

188188
koreJsonLogAction =
189189
koreSomeEntryLogAction
190190
(renderJson (ExeName "") (TimeSpec 0 0) TimestampsDisable)
191191
logAsJson
192+
(const True)
192193
( LogAction $ \txt ->
193194
let bytes = Text.encodeUtf8 $ prefix txt <> "\n"
194195
in liftIO $ do
@@ -206,12 +207,7 @@ main = do
206207
, Log.timestampsSwitch = TimestampsDisable
207208
, Log.debugSolverOptions =
208209
Log.DebugSolverOptions . fmap (<> ".kore") $ smtOptions >>= (.transcript)
209-
, Log.logType =
210-
LogProxy $
211-
Log.LogProxyActionData
212-
{ messageFilter = const True
213-
, logActions = koreLogActions
214-
}
210+
, Log.logType = LogProxy (mconcat koreLogActions)
215211
, Log.logFormat = Log.Standard
216212
}
217213
srvSettings = serverSettings port "*"

kore/src/Kore/Log/BoosterAdaptor.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Data.Functor.Contravariant (
2828
import Data.Text (
2929
Text,
3030
)
31+
import Data.Text qualified as Text
3132
import Data.Text.Lazy qualified as LazyText
3233
import Kore.JsonRpc.Types.Log (LogOrigin (KoreRpc))
3334
import Kore.Log (WithTimestamp (..), swappableLogger, withTimestamp)
@@ -65,20 +66,25 @@ withMainLogger koreLogOptions = runContT $ do
6566
. Log.koreLogTransformer koreLogOptions
6667
. Log.koreLogFilters koreLogOptions
6768
$ case logType koreLogOptions of
68-
LogProxy LogProxyActionData{logActions} -> mconcat logActions
69+
LogProxy logAction -> logAction
6970
ltype -> error ("Unexpected log type " <> show ltype)
7071

7172
koreSomeEntryLogAction ::
7273
MonadIO m =>
74+
-- | how to render a timestamped 'SomeEntry' into Text
7375
(WithTimestamp -> Text) ->
76+
-- | filter log entries, applies BEFORE rendering to text
7477
(SomeEntry -> Bool) ->
78+
-- | filter log entries, applies AFTER rendering to text
79+
(Text -> Bool) ->
7580
LogAction m Text ->
7681
LogAction m SomeEntry
77-
koreSomeEntryLogAction renderer selector textLogAction =
82+
koreSomeEntryLogAction renderer earlyFilter lateFilter textLogAction =
7883
textLogAction
84+
& Colog.cfilter lateFilter
7985
& contramap renderer
8086
& Colog.cmapM withTimestamp
81-
& Colog.cfilter selector
87+
& Colog.cfilter earlyFilter
8288

8389
renderJson :: ExeName -> TimeSpec -> TimestampsSwitch -> WithTimestamp -> Text
8490
renderJson _exeName _startTime _timestampSwitch (WithTimestamp (SomeEntry _context actualEntry) _entryTime) =

kore/src/Kore/Log/KoreLogOptions.hs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ License : BSD-3-Clause
77
module Kore.Log.KoreLogOptions (
88
KoreLogOptions (..),
99
KoreLogType (..),
10-
LogProxyActionData (..),
1110
KoreLogFormat (..),
1211
EntryTypes,
1312
ExeName (..),
@@ -166,16 +165,8 @@ data KoreLogType
166165
LogStdErr
167166
| -- | Log to specified file when '--log <filename>' is passed.
168167
LogFileText FilePath
169-
| -- | Log actions forwarded from proxy servers (e.g. kore-rpc-booster, kore-rpc-dev)
170-
LogProxy LogProxyActionData
171-
172-
-- | Log actions forwarded from 'booster/Server.hs'
173-
data LogProxyActionData = LogProxyActionData
174-
{ messageFilter :: (Text -> Bool)
175-
-- ^ which messages to log
176-
, logActions :: (forall m. MonadIO m => [LogAction m SomeEntry])
177-
-- ^ actual log actions
178-
}
168+
| -- | Log action forwarded from proxy servers (e.g. kore-rpc-booster, kore-rpc-dev)
169+
LogProxy (forall m. MonadIO m => LogAction m SomeEntry)
179170

180171
instance Eq KoreLogType where
181172
LogStdErr == LogStdErr = True

0 commit comments

Comments
 (0)