{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
module Serokell.Util.Trace
( traceIdF
) where
import Universum
import Data.Text (Text)
import Formatting (Format, now, sformat)
import Formatting.Internal (runFormat)
class VarArgTrace fmt f | fmt -> f where
traceIdFHelper :: fmt -> f
instance {-# OVERLAPPING #-}
Print p => VarArgTrace (x -> p) (x -> x) where
traceIdFHelper fmt x = trace (fmt x) x
instance VarArgTrace fmt f => VarArgTrace (a -> fmt) (a -> f) where
traceIdFHelper fmt a = traceIdFHelper (fmt a)
{-# WARNING traceIdF "'traceIdF' remains in code" #-}
traceIdF :: VarArgTrace fmt a => Format Text fmt -> a
traceIdF fmt = traceIdFHelper (runFormat fmt (sformat . now))