Skip to content

Commit a4167e5

Browse files
jutaromgmeier
authored andcommitted
cardano-tracer: correctly observe CLI option --min-log-severity
1 parent 51fe548 commit a4167e5

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

cardano-tracer/src/Cardano/Tracer/CLI.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ parseTracerParams = TracerParams
3838
( option auto
3939
( long "min-log-severity"
4040
<> metavar "SEVERITY"
41-
<> help "Drop messages less severe than this. One of: Debug. Info. Notice. Warning. Error. Critical. Alert. Emergency."
41+
<> help "Drop messages less severe than this. <Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency> (default: Info)"
4242
)
4343
)

cardano-tracer/src/Cardano/Tracer/MetaTrace.hs

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ module Cardano.Tracer.MetaTrace
2323
import Cardano.Logging
2424
import Cardano.Logging.Resources
2525
import Cardano.Tracer.Configuration
26-
import Cardano.Tracer.Types (NodeId(..), NodeName)
26+
import Cardano.Tracer.Types (NodeId (..), NodeName)
2727

2828
import Data.Aeson hiding (Error)
2929
import qualified Data.Aeson as AE
30-
import Data.Function
3130
import qualified Data.Map.Strict as Map
3231
import Data.Text (Text)
3332
import qualified Data.Text as T
@@ -198,11 +197,7 @@ instance LogFormatting TracerTrace where
198197
, "Enable with `-f +rtview`."
199198
]
200199
forHuman t = T.pack (show t)
201-
202-
forMachine DMinimal _ = mempty
203-
forMachine DNormal _ = mempty
204-
forMachine DDetailed t = forMachine DMaximum t
205-
forMachine DMaximum t = case AE.toJSON t of
200+
forMachine _ t = case AE.toJSON t of
206201
AE.Object x -> x
207202
_ -> error "Impossible"
208203

@@ -230,6 +225,7 @@ instance MetaTrace TracerTrace where
230225
namespaceFor TracerError {} = Namespace [] ["Error"]
231226
namespaceFor TracerResource {} = Namespace [] ["Resource"]
232227

228+
severityFor (Namespace _ ["BuildInfo"]) _ = Just Info
233229
severityFor (Namespace _ ["ParamsAre"]) _ = Just Warning
234230
severityFor (Namespace _ ["ConfigIs"]) _ = Just Warning
235231
severityFor (Namespace _ ["InitStart"]) _ = Just Info
@@ -256,7 +252,8 @@ instance MetaTrace TracerTrace where
256252
documentFor _ = Just ""
257253

258254
allNamespaces = [
259-
Namespace [] ["ParamsAre"]
255+
Namespace [] ["BuildInfo"]
256+
, Namespace [] ["ParamsAre"]
260257
, Namespace [] ["ConfigIs"]
261258
, Namespace [] ["InitStart"]
262259
, Namespace [] ["EventQueues"]
@@ -283,40 +280,23 @@ stderrShowTracer :: Trace IO TracerTrace
283280
stderrShowTracer = contramapM'
284281
(either (const $ pure ()) (Sys.hPrint Sys.stderr) . snd)
285282

286-
stderrTracer :: Trace IO FormattedMessage
287-
stderrTracer =
288-
contramapM'
289-
(either (const $ pure ()) (Sys.hPutStrLn Sys.stderr . T.unpack . render) . snd)
290-
where
291-
render = \case
292-
FormattedHuman _ x -> x
293-
FormattedMachine x -> x
294-
_ -> ""
295-
296283
mkTracerTracer :: SeverityF -> IO (Trace IO TracerTrace)
297284
mkTracerTracer defSeverity = do
298-
base :: Trace IO FormattedMessage <- standardTracer
299-
metaBase :: Trace IO TracerTrace <-
300-
machineFormatter base
301-
>>= withDetailsFromConfig
302-
let tr = metaBase
303-
& withInnerNames
304-
& appendPrefixName "Tracer"
305-
& withSeverity
285+
standardTracer
286+
>>= machineFormatter
287+
>>= filterSeverityFromConfig
288+
>>= \t ->
289+
let finalTracer = withNames ["Tracer"] (withSeverity t)
290+
in configTracerTracer defSeverity finalTracer >> pure finalTracer
291+
292+
configTracerTracer :: SeverityF -> Trace IO TracerTrace -> IO ()
293+
configTracerTracer defSeverity tr = do
306294
configReflection <- emptyConfigReflection
307295
configureTracers configReflection initialTraceConfig [tr]
308-
pure tr
309296
where
310297
initialTraceConfig :: TraceConfig
311298
initialTraceConfig =
312-
TraceConfig
313-
{ tcForwarder = Nothing
314-
, tcNodeName = Nothing
315-
, tcPeerFrequency = Nothing
316-
, tcResourceFrequency = Nothing
317-
, tcMetricsPrefix = Nothing
318-
, tcOptions = Map.fromList
319-
[ ([], [ConfSeverity defSeverity])
320-
, (["Tracer"], [ConfDetail DMaximum])
321-
]
299+
emptyTraceConfig
300+
{
301+
tcOptions = Map.fromList [([], [ConfSeverity defSeverity])]
322302
}

cardano-tracer/src/Cardano/Tracer/Run.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Cardano.Tracer.MetaTrace
2626
import Cardano.Tracer.Types
2727
import Cardano.Tracer.Utils
2828

29+
import Control.Applicative
2930
import Control.Concurrent (threadDelay)
3031
import Control.Concurrent.Async (async, link)
3132
import Control.Concurrent.Extra (newLock)
@@ -45,7 +46,7 @@ import Data.Text.Lazy.Builder as TB (Builder, fromText)
4546
-- | Top-level run function, called by 'cardano-tracer' app.
4647
runCardanoTracer :: TracerParams -> IO ()
4748
runCardanoTracer TracerParams{tracerConfig, stateDir, logSeverity} = do
48-
tr <- mkTracerTracer $ SeverityF logSeverity
49+
tr <- mkTracerTracer $ SeverityF $ logSeverity <|> Just Info -- default severity filter to Info
4950
traceWith tr TracerBuildInfo
5051
#if RTVIEW
5152
{ ttBuiltWithRTView = True

0 commit comments

Comments
 (0)