{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE TypeOperators              #-}

-- |
-- Module      :  Network.Ipfs.Api.Log
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  unknown
--
-- Api calls with `log` prefix.
--

module Network.Ipfs.Api.Log where

import           Control.Monad.IO.Class           (MonadIO)
import           Data.Text                        (Text)

import           Network.Ipfs.Api.Internal        (_logLevel, _logLs)
import           Network.Ipfs.Api.Internal.Call   (call, streamCall)
import           Network.Ipfs.Api.Internal.Stream (_logTail)
import           Network.Ipfs.Api.Types           (LogLevelObj, LogLsObj)
import           Network.Ipfs.Client              (IpfsT)


-- | Change the logging level.
level :: MonadIO m => Text -> Text -> IpfsT m LogLevelObj
level :: Text -> Text -> IpfsT m LogLevelObj
level Text
subsystem = ClientM LogLevelObj -> IpfsT m LogLevelObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM LogLevelObj -> IpfsT m LogLevelObj)
-> (Text -> ClientM LogLevelObj) -> Text -> IpfsT m LogLevelObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> ClientM LogLevelObj
_logLevel Text
subsystem (Maybe Text -> ClientM LogLevelObj)
-> (Text -> Maybe Text) -> Text -> ClientM LogLevelObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Read the event log.
tail :: MonadIO m => m ()
tail :: m ()
tail = ClientM (SourceT IO Text) -> m ()
forall (m :: * -> *) a.
(MonadIO m, Show a) =>
ClientM (SourceT IO a) -> m ()
streamCall ClientM (SourceT IO Text)
_logTail

-- | List the logging subsystems.
ls :: MonadIO m => IpfsT m LogLsObj
ls :: IpfsT m LogLsObj
ls = ClientM LogLsObj -> IpfsT m LogLsObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM LogLsObj
_logLs