|
2 | 2 | {-# LANGUAGE DeriveGeneric #-} |
3 | 3 | {-# LANGUAGE DerivingStrategies #-} |
4 | 4 | {-# LANGUAGE GADTs #-} |
5 | | -{-# LANGUAGE MultiWayIf #-} |
6 | 5 | {-# LANGUAGE RankNTypes #-} |
7 | 6 | {-# LANGUAGE RecordWildCards #-} |
8 | 7 | {-# LANGUAGE ScopedTypeVariables #-} |
9 | | -{-# LANGUAGE StandaloneKindSignatures #-} |
10 | 8 |
|
11 | 9 | {-# OPTIONS_GHC -Wno-partial-fields #-} |
12 | 10 |
|
@@ -44,39 +42,28 @@ module Cardano.Logging.Types ( |
44 | 42 | , emptyConfigReflection |
45 | 43 | , TraceConfig(..) |
46 | 44 | , emptyTraceConfig |
47 | | - , FormattedMessage(..) |
48 | 45 | , TraceControl(..) |
49 | 46 | , DocCollector(..) |
50 | 47 | , LogDoc(..) |
51 | 48 | , emptyLogDoc |
52 | 49 | , BackendConfig(..) |
53 | 50 | , Folding(..) |
54 | 51 | , unfold |
55 | | - , TraceObject(..) |
56 | | - , PreFormatted(..) |
57 | | - , HowToConnect(..) |
58 | 52 | ) where |
59 | 53 |
|
60 | 54 | import Codec.Serialise (Serialise (..)) |
61 | | -import Control.Applicative ((<|>)) |
62 | 55 | import Control.DeepSeq (NFData) |
63 | 56 | import qualified Control.Tracer as T |
64 | 57 | import qualified Data.Aeson as AE |
65 | | -import qualified Data.Aeson.Types as AE (Parser) |
66 | 58 | import Data.Bool (bool) |
67 | | -import Data.ByteString (ByteString) |
68 | 59 | import Data.IORef |
69 | | -import Data.Kind (Type) |
70 | 60 | import Data.Map.Strict (Map) |
71 | 61 | import qualified Data.Map.Strict as Map |
72 | 62 | import Data.Set (Set) |
73 | 63 | import qualified Data.Set as Set |
74 | | -import Data.Text as T (Text, breakOnEnd, intercalate, null, |
75 | | - pack, singleton, unpack, unsnoc, |
76 | | - words) |
| 64 | +import Data.Text as T (Text, intercalate, null, |
| 65 | + pack, singleton, unpack, words) |
77 | 66 | import Data.Text.Read as T (decimal) |
78 | | -import Data.Time (UTCTime) |
79 | | -import Data.Word (Word16) |
80 | 67 | import GHC.Generics |
81 | 68 | import Network.HostName (HostName) |
82 | 69 | import Network.Socket (PortNumber) |
@@ -334,40 +321,6 @@ emptyConfigReflection = do |
334 | 321 | allTracers <- newIORef Set.empty |
335 | 322 | pure $ ConfigReflection silence hasMetrics allTracers |
336 | 323 |
|
337 | | -data FormattedMessage = |
338 | | - FormattedHuman Bool Text |
339 | | - -- ^ The bool specifies if the formatting includes colours |
340 | | - | FormattedMachine Text |
341 | | - | FormattedMetrics [Metric] |
342 | | - | FormattedForwarder TraceObject |
343 | | - | FormattedCBOR ByteString |
344 | | - deriving stock (Eq, Show) |
345 | | - |
346 | | - |
347 | | -data PreFormatted = PreFormatted { |
348 | | - pfTime :: !UTCTime |
349 | | - , pfNamespace :: !Text |
350 | | - , pfThreadId :: !Text |
351 | | - , pfForHuman :: !(Maybe Text) |
352 | | - , pfForMachineObject :: AE.Object |
353 | | -} |
354 | | - |
355 | | --- | Used as interface object for ForwarderTracer |
356 | | -data TraceObject = TraceObject { |
357 | | - toHuman :: !(Maybe Text) |
358 | | - , toMachine :: !Text |
359 | | - , toNamespace :: ![Text] |
360 | | - , toSeverity :: !SeverityS |
361 | | - , toDetails :: !DetailLevel |
362 | | - , toTimestamp :: !UTCTime |
363 | | - , toHostname :: !Text |
364 | | - , toThreadId :: !Text |
365 | | -} deriving stock |
366 | | - (Eq, Show, Generic) |
367 | | - -- ^ Instances for 'TraceObject' to forward it using 'trace-forward' library. |
368 | | - deriving anyclass |
369 | | - (Serialise, NFData) |
370 | | - |
371 | 324 | -- | |
372 | 325 | data BackendConfig = |
373 | 326 | Forwarder |
@@ -613,55 +566,3 @@ instance LogFormatting b => LogFormatting (Folding a b) where |
613 | 566 | forHuman (Folding b) = forHuman b |
614 | 567 | asMetrics (Folding b) = asMetrics b |
615 | 568 |
|
616 | | --- | Specifies how to connect to the peer. |
617 | | --- |
618 | | --- Taken from ekg-forward:System.Metrics.Configuration, to avoid dependency. |
619 | | -type Host :: Type |
620 | | -type Host = Text |
621 | | - |
622 | | -type Port :: Type |
623 | | -type Port = Word16 |
624 | | - |
625 | | -type HowToConnect :: Type |
626 | | -data HowToConnect |
627 | | - = LocalPipe !FilePath -- ^ Local pipe (UNIX or Windows). |
628 | | - | RemoteSocket !Host !Port -- ^ Remote socket (host and port). |
629 | | - deriving stock (Eq, Generic) |
630 | | - deriving anyclass (NFData) |
631 | | - |
632 | | -instance Show HowToConnect where |
633 | | - show = \case |
634 | | - LocalPipe pipe -> pipe |
635 | | - RemoteSocket host port -> T.unpack host ++ ":" ++ show port |
636 | | - |
637 | | -instance AE.ToJSON HowToConnect where |
638 | | - toJSON = AE.toJSON . show |
639 | | - toEncoding = AE.toEncoding . show |
640 | | - |
641 | | --- first try to host:port, and if that fails revert to parsing any |
642 | | --- string literal and assume it is a localpipe. |
643 | | -instance AE.FromJSON HowToConnect where |
644 | | - parseJSON = AE.withText "HowToConnect" $ \t -> |
645 | | - (uncurry RemoteSocket <$> parseHostPort t) |
646 | | - <|> ( LocalPipe <$> parseLocalPipe t) |
647 | | - |
648 | | -parseLocalPipe :: Text -> AE.Parser FilePath |
649 | | -parseLocalPipe t |
650 | | - | T.null t = fail "parseLocalPipe: empty Text" |
651 | | - | otherwise = pure $ T.unpack t |
652 | | - |
653 | | -parseHostPort :: Text -> AE.Parser (Text, Word16) |
654 | | -parseHostPort t |
655 | | - | T.null t |
656 | | - = fail "parseHostPort: empty Text" |
657 | | - | otherwise |
658 | | - = let |
659 | | - (host_, portText) = T.breakOnEnd ":" t |
660 | | - host = maybe "" fst (T.unsnoc host_) |
661 | | - in if |
662 | | - | T.null host -> fail "parseHostPort: Empty host or no colon found." |
663 | | - | T.null portText -> fail "parseHostPort: Empty port." |
664 | | - | Right (port, remainder) <- T.decimal portText |
665 | | - , T.null remainder |
666 | | - , 0 <= port, port <= 65535 -> pure (host, port) |
667 | | - | otherwise -> fail "parseHostPort: Non-numeric port or value out of range." |
0 commit comments