{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports    #-}

--------------------------------------------------------------------------------

-- Orphan instances module for Cardano tracer.
{-# OPTIONS_GHC -Wno-orphans #-}
-- Extracted from "cardano-node" `Cardano.Node.Tracing.Tracers.Consensus`.
-- Branch "master" (2026-02-11, 85869e9dd21d9dac7c4381418346e97259c3303b).

--------------------------------------------------------------------------------

module Ouroboros.Network.Tracing.ConnectionId () where

--------------------------------------------------------------------------------

---------
-- base -
---------
--
---------------------
-- Package: "aeson" -
---------------------
import "aeson" Data.Aeson (Value (String), (.=))
---------------------------------
-- Package: "ouroboros-network" -
---------------------------------
import "ouroboros-network" Ouroboros.Network.ConnectionId (ConnectionId (..))
--------------------------------
-- Package: "trace-dispatcher" -
--------------------------------
import "trace-dispatcher" Cardano.Logging

--------------------------------------------------------------------------------
-- Types instances.
--------------------------------------------------------------------------------

instance (LogFormatting adr, Show adr) => LogFormatting (ConnectionId adr) where
  forMachine :: DetailLevel -> ConnectionId adr -> Object
forMachine DetailLevel
_dtal (ConnectionId adr
local' adr
remote) =
    [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"connectionId" Key -> Value -> Object
forall v. ToJSON v => Key -> v -> Object
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (adr -> Text
forall a. Show a => a -> Text
showT adr
local'
                                          Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" "
                                          Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> adr -> Text
forall a. Show a => a -> Text
showT adr
remote)
    ]
  forHuman :: ConnectionId adr -> Text
forHuman (ConnectionId adr
local' adr
remote) =
    Text
"ConnectionId " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>  adr -> Text
forall a. Show a => a -> Text
showT adr
local' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> adr -> Text
forall a. Show a => a -> Text
showT adr
remote