Skip to content

Commit b7d7870

Browse files
committed
trace-dispatcher: showT
disable warning for ghc 9 Fix cabal file Change of own messages
1 parent d1d0c2d commit b7d7870

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

trace-dispatcher/src/Cardano/Logging.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ import Cardano.Logging.Tracer.EKG as X
1515
import Cardano.Logging.Tracer.Forward as X
1616
import Cardano.Logging.Tracer.Standard as X
1717
import Cardano.Logging.Types as X
18+
import Cardano.Logging.Utils as X
1819
import Control.Tracer as X hiding (Tracer, nullTracer, traceWith)

trace-dispatcher/src/Cardano/Logging/DocuGenerator.hs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,32 @@ module Cardano.Logging.DocuGenerator (
2525
, DocTracer
2626
) where
2727

28+
import Prelude hiding (lines, unlines)
2829

2930
import Data.IORef (modifyIORef, newIORef, readIORef)
3031
import Data.List (groupBy, intersperse, nub, sortBy)
3132
import qualified Data.Map.Strict as Map
3233
import Data.Maybe (fromMaybe, mapMaybe)
33-
import Data.Text (Text, pack, toLower)
34-
import qualified Data.Text as T
34+
import Data.Text (Text, lines, split, toLower, unlines)
3535
import Data.Text.Internal.Builder (toLazyText)
3636
import Data.Text.Lazy (toStrict)
3737
import Data.Text.Lazy.Builder (Builder, fromString, fromText, singleton)
3838
import Data.Time (getZonedTime)
3939

4040
import Cardano.Logging.Types
4141
import Control.Monad.IO.Class (MonadIO, liftIO)
42-
import qualified Control.Tracer as T
42+
import qualified Control.Tracer as TR
4343

44+
import Cardano.Logging.Utils (showT)
4445
import Trace.Forward.Utils.DataPoint (DataPoint (..))
4546

46-
47-
4847
-- | Convenience function for adding a namespace prefix to a documented
4948
addDocumentedNamespace :: [Text] -> Documented a -> Documented a
5049
addDocumentedNamespace tl (Documented list) =
5150
Documented $ map
5251
(\ dm@DocMsg {} -> dm {dmNamespace = nsReplacePrefix (dmNamespace dm) tl})
5352
list
5453

55-
-- | Convenience function
56-
{-# INLINE showT #-}
57-
showT :: Show a => a -> Text
58-
showT = pack . show
59-
6054
data DocuResult =
6155
DocuTracer Builder
6256
| DocuMetric Builder
@@ -294,7 +288,7 @@ documentTracersRun tracers = do
294288
, ldPrivacyCoded = privacyFor ns Nothing
295289
, ldDetailsCoded = detailsFor ns Nothing
296290
}))
297-
T.traceWith tr (emptyLoggingContext {lcNSInner = nsGetInner ns},
291+
TR.traceWith tr (emptyLoggingContext {lcNSInner = nsGetInner ns},
298292
Left (TCDocument idx dc)))
299293
nsIdx
300294

@@ -303,7 +297,7 @@ documentTracersRun tracers = do
303297
docTracer :: MonadIO m =>
304298
BackendConfig
305299
-> Trace m FormattedMessage
306-
docTracer backendConfig = Trace $ T.arrow $ T.emit output
300+
docTracer backendConfig = Trace $ TR.arrow $ TR.emit output
307301
where
308302
output p@(_, Left TCDocument {}) =
309303
docIt backendConfig p
@@ -312,7 +306,7 @@ docTracer backendConfig = Trace $ T.arrow $ T.emit output
312306
docTracerDatapoint :: MonadIO m =>
313307
BackendConfig
314308
-> Trace m DataPoint
315-
docTracerDatapoint backendConfig = Trace $ T.arrow $ T.emit output
309+
docTracerDatapoint backendConfig = Trace $ TR.arrow $ TR.emit output
316310
where
317311
output p@(_, Left TCDocument {}) =
318312
docItDatapoint backendConfig p
@@ -530,7 +524,7 @@ generateTOC dt traces metrics datapoints =
530524
[] -> error "inpossible"
531525

532526
splitToNS :: [Text] -> [Text]
533-
splitToNS [sym] = T.split (== '.') sym
527+
splitToNS [sym] = split (== '.') sym
534528
splitToNS other = other
535529

536530

@@ -562,4 +556,4 @@ accentuated :: Text -> Builder
562556
accentuated t = if t == ""
563557
then fromText "\n"
564558
else fromText "\n"
565-
<> fromText (T.unlines $ map ("> " <>) (T.lines t))
559+
<> fromText (unlines $ map ("> " <>) (lines t))

trace-dispatcher/src/Cardano/Logging/TraceDispatcherMessage.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ instance LogFormatting TraceDispatcherMessage where
4646
". Suppressed " <> pack (show num) <> " messages."
4747
forHuman (RememberLimiting txt num) = "Frequency limiting still active for " <> txt <>
4848
". Suppressed so far " <> pack (show num) <> " messages."
49-
forHuman (UnknownNamespace nsUnknown nsLegal qk) = "Unknown namespace detected "
50-
<> intercalate (singleton '.') nsUnknown <> ". Used for querying " <> (pack . show) qk
51-
<> " a legal namespace would be " <> intercalate (singleton '.') nsLegal <> "."
49+
forHuman (UnknownNamespace nsPrefixNS nsInnerNS qk) = "Unknown namespace detected "
50+
<> intercalate (singleton '.') (nsPrefixNS ++ nsInnerNS)
51+
<> ". Used for querying " <> (pack . show) qk <> "."
5252
forHuman (TracerInfo silent noMetrics allTracers) = "The tracing system has silent the following tracer,"
5353
<> " as they will never have any output according to the current config: "
5454
<> intercalate (singleton ' ') silent <> ". The following tracers will not emit metrics "

trace-dispatcher/src/Cardano/Logging/Tracer/Composed.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mkCardanoTracer' trStdout trForward mbTrEkg tracerPrefix hook = do
7171
trForward
7272
Nothing
7373
(Trace T.nullTracer)
74+
>>= addContextAndFilter
7475

7576
-- handle the messages
7677
!messageTrace <- withBackendsFromConfig (backendsAndFormat trStdout trForward)
@@ -92,7 +93,7 @@ mkCardanoTracer' trStdout trForward mbTrEkg tracerPrefix hook = do
9293
pure (messageTrace <> metricsTrace)
9394

9495
where
95-
addContextAndFilter :: Trace IO evt1 -> IO (Trace IO evt1)
96+
addContextAndFilter :: MetaTrace a => Trace IO a -> IO (Trace IO a)
9697
addContextAndFilter tr = do
9798
tr' <- withDetailsFromConfig tr
9899
tr'' <- filterSeverityFromConfig tr'

trace-dispatcher/src/Cardano/Logging/Utils.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
{-# LANGUAGE LambdaCase #-}
22

3+
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
4+
-- showHex needs to be a show instance on ghc8, but not any more on ghc9
5+
36
module Cardano.Logging.Utils (
47
runInLoop
58
, uncurry3
69
, mapSnd
10+
, showT
11+
, showTHex
712
) where
813

914
import Control.Concurrent (threadDelay)
1015
import Control.Exception (SomeAsyncException (..), fromException, tryJust)
1116
import Control.Tracer (stdoutTracer, traceWith)
17+
import qualified Data.Text as T
18+
import Numeric (showHex)
1219

1320
-- | Run monadic action in a loop. If there's an exception, it will re-run
1421
-- the action again, after pause that grows.
@@ -39,3 +46,13 @@ uncurry3 f (a,b,c) = f a b c
3946

4047
mapSnd :: (a -> b) -> (c, a) -> (c, b)
4148
mapSnd f (x,y) = (x,f y)
49+
50+
-- | Convenience function
51+
{-# INLINE showT #-}
52+
showT :: Show a => a -> T.Text
53+
showT = T.pack . show
54+
55+
-- | Convenience function
56+
{-# INLINE showTHex #-}
57+
showTHex :: (Integral a, Show a) => a -> T.Text
58+
showTHex i = T.pack (showHex i [])

trace-dispatcher/trace-dispatcher.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ maintainer: operations@iohk.io
1313
license: Apache-2.0
1414
license-files: LICENSE
1515
NOTICE
16-
extra-source-files: CHANGELOG.md
16+
extra-doc-files: CHANGELOG.md
1717
README.md
1818
doc/trace-dispatcher.md
1919

2020
common project-config
2121
default-language: Haskell2010
2222

2323
library
24+
import: project-config
2425
hs-source-dirs: src
2526
exposed-modules: Cardano.Logging
2627
Cardano.Logging.Configuration
@@ -129,6 +130,7 @@ executable trace-dispatcher-examples
129130
-Wno-incomplete-patterns
130131

131132
test-suite trace-dispatcher-test
133+
import: project-config
132134
type: exitcode-stdio-1.0
133135
hs-source-dirs: test
134136
main-is: trace-dispatcher-test.hs

0 commit comments

Comments
 (0)