{-# LANGUAGE OverloadedStrings #-}

module Plutus.PAB.Monitoring.Config (
      defaultConfig
    , loadConfig
    ) where

import Cardano.BM.Configuration (setup)
import Cardano.BM.Configuration.Model qualified as CM
import Cardano.BM.Data.BackendKind
import Cardano.BM.Data.Configuration (Endpoint (..))
import Cardano.BM.Data.Output
import Cardano.BM.Data.Severity

-- | A default 'CM.Configuration' that logs on 'Info' and above
--   to stdout
defaultConfig :: IO CM.Configuration
defaultConfig :: IO Configuration
defaultConfig = do
  Configuration
c <- IO Configuration
CM.empty
  Configuration -> Severity -> IO ()
CM.setMinSeverity Configuration
c Severity
Info
  Configuration -> [BackendKind] -> IO ()
CM.setSetupBackends Configuration
c [ BackendKind
KatipBK
                        , BackendKind
AggregationBK
                        , BackendKind
MonitoringBK
                        , BackendKind
EKGViewBK
                        ]
  Configuration -> [BackendKind] -> IO ()
CM.setDefaultBackends Configuration
c [BackendKind
KatipBK, BackendKind
AggregationBK, BackendKind
EKGViewBK]
  Configuration -> [ScribeDefinition] -> IO ()
CM.setSetupScribes Configuration
c [ ScribeDefinition :: ScribeKind
-> ScribeFormat
-> Text
-> ScribePrivacy
-> Maybe RotationParameters
-> Severity
-> Severity
-> ScribeDefinition
ScribeDefinition {
                          scName :: Text
scName = Text
"stdout"
                        , scKind :: ScribeKind
scKind = ScribeKind
StdoutSK
                        , scFormat :: ScribeFormat
scFormat = ScribeFormat
ScText
                        , scPrivacy :: ScribePrivacy
scPrivacy = ScribePrivacy
ScPublic
                        , scRotation :: Maybe RotationParameters
scRotation = Maybe RotationParameters
forall a. Maybe a
Nothing
                        , scMinSev :: Severity
scMinSev = Severity
forall a. Bounded a => a
minBound
                        , scMaxSev :: Severity
scMaxSev = Severity
forall a. Bounded a => a
maxBound
                        }]
  Configuration -> [Text] -> IO ()
CM.setDefaultScribes Configuration
c [Text
"StdoutSK::stdout"]
  Configuration -> Maybe Endpoint -> IO ()
CM.setEKGBindAddr Configuration
c (Maybe Endpoint -> IO ()) -> Maybe Endpoint -> IO ()
forall a b. (a -> b) -> a -> b
$ Endpoint -> Maybe Endpoint
forall a. a -> Maybe a
Just (HostPort -> Endpoint
Endpoint (String
"127.0.0.1", Port
12790))
  Configuration -> IO Configuration
forall (f :: * -> *) a. Applicative f => a -> f a
pure Configuration
c

-- | Load a 'CM.Configuration' from a YAML file.
loadConfig :: FilePath -> IO CM.Configuration
loadConfig :: String -> IO Configuration
loadConfig = String -> IO Configuration
setup