diff --git a/examples/mig-example-apps/RouteArgs/Main.hs b/examples/mig-example-apps/RouteArgs/Main.hs index f3a2819..7a915a6 100644 --- a/examples/mig-example-apps/RouteArgs/Main.hs +++ b/examples/mig-example-apps/RouteArgs/Main.hs @@ -21,7 +21,7 @@ main = do routeArgs :: Server IO routeArgs = withSwagger def $ - withTrace $ + Trace.withLogs $ "api" /. -- no args, constnat output @@ -41,8 +41,6 @@ routeArgs = , -- return error "square-root" /. handleSquareRoot ] - where - withTrace = applyPlugin (Trace.logHttp Trace.V2) -- | Simple getter helloWorld :: Get (Resp Text) diff --git a/mig-extra/src/Mig/Extra/Plugin/Trace.hs b/mig-extra/src/Mig/Extra/Plugin/Trace.hs index 9ab9cfd..0b2ec72 100644 --- a/mig-extra/src/Mig/Extra/Plugin/Trace.hs +++ b/mig-extra/src/Mig/Extra/Plugin/Trace.hs @@ -16,6 +16,8 @@ module Mig.Extra.Plugin.Trace ( logHttpBy, ppReq, Verbosity (..), + withLogs, + withLogsBy, ) where import Control.Monad @@ -57,6 +59,12 @@ ifLevel current level vals | level <= current = vals | otherwise = [] +withLogs :: (MonadIO m) => Server m -> Server m +withLogs = applyPlugin (logHttp V2) + +withLogsBy :: (MonadIO m) => (Json.Value -> m ()) -> Server m -> Server m +withLogsBy toLogItem = applyPlugin (logHttpBy toLogItem V2) + ------------------------------------------------------------------------------------- -- through diff --git a/mig-extra/src/Mig/Extra/Server/Common.hs b/mig-extra/src/Mig/Extra/Server/Common.hs index 9acbddd..acd56d6 100644 --- a/mig-extra/src/Mig/Extra/Server/Common.hs +++ b/mig-extra/src/Mig/Extra/Server/Common.hs @@ -127,7 +127,9 @@ import Control.Monad.IO.Class as X import Control.Monad.Trans.Class as X import Data.Aeson as X (FromJSON (..), ToJSON (..)) import Data.Default as X +import Data.Maybe as X import Data.OpenApi as X (OpenApi, ToParamSchema (..), ToSchema (..)) +import Data.String as X import Data.Text as X (Text) import GHC.Generics as X (Generic) import Mig.Extra.Derive as X diff --git a/mig-server/src/Mig.hs b/mig-server/src/Mig.hs index 9a3151c..9944cff 100644 --- a/mig-server/src/Mig.hs +++ b/mig-server/src/Mig.hs @@ -163,7 +163,9 @@ import Control.Monad.IO.Class as X import Control.Monad.Trans.Class as X import Data.Aeson as X (FromJSON (..), ToJSON (..)) import Data.Default as X +import Data.Maybe as X import Data.OpenApi as X (OpenApi, ToParamSchema (..), ToSchema (..)) +import Data.String as X import Data.Text as X (Text) import GHC.Generics as X (Generic) import Network.HTTP.Types.Header as X (RequestHeaders, ResponseHeaders)