Skip to content

Commit 1786c71

Browse files
committed
Add terminal to StackLoggingT environment
1 parent 7b72c51 commit 1786c71

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/Stack/Types/StackT.hs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ runStackT manager logLevel config terminal m =
9393
--------------------------------------------------------------------------------
9494
-- Logging only StackLoggingT monad transformer
9595

96+
-- | Monadic environment for 'StackLoggingT'.
97+
data LoggingEnv = LoggingEnv
98+
{ lenvLogLevel :: !LogLevel
99+
, lenvTerminal :: !Bool
100+
, lenvManager :: !Manager
101+
, lenvSticky :: !Sticky
102+
}
103+
96104
-- | The monad used for logging in the executable @stack@ before
97105
-- anything has been initialized.
98-
newtype StackLoggingT m a =
99-
StackLoggingT {unStackLoggingT :: ReaderT (LogLevel,Manager,Sticky) m a}
100-
deriving (Functor,Applicative,Monad,MonadIO,MonadThrow,MonadReader (LogLevel,Manager,Sticky),MonadCatch,MonadMask,MonadTrans)
106+
newtype StackLoggingT m a = StackLoggingT
107+
{ unStackLoggingT :: ReaderT LoggingEnv m a
108+
} deriving (Functor,Applicative,Monad,MonadIO,MonadThrow,MonadReader LoggingEnv,MonadCatch,MonadMask,MonadTrans)
101109

102110
deriving instance (MonadBase b m) => MonadBase b (StackLoggingT m)
103111

@@ -107,22 +115,25 @@ instance MonadBaseControl b m => MonadBaseControl b (StackLoggingT m) where
107115
restoreM = defaultRestoreM
108116

109117
instance MonadTransControl StackLoggingT where
110-
type StT StackLoggingT a = StT (ReaderT (LogLevel,Manager,Sticky)) a
118+
type StT StackLoggingT a = StT (ReaderT LoggingEnv) a
111119
liftWith = defaultLiftWith StackLoggingT unStackLoggingT
112120
restoreT = defaultRestoreT StackLoggingT
113121

114122
-- | Takes the configured log level into account.
115123
instance (MonadIO m) => MonadLogger (StackLoggingT m) where
116-
monadLoggerLog = stickyLoggerFunc
124+
monadLoggerLog = stickyLoggerFunc
125+
126+
instance HasSticky LoggingEnv where
127+
getSticky = lenvSticky
117128

118-
instance HasSticky (LogLevel,Manager,Sticky) where
119-
getSticky (_,_,s) = s
129+
instance HasLogLevel LoggingEnv where
130+
getLogLevel = lenvLogLevel
120131

121-
instance HasLogLevel (LogLevel,Manager,Sticky) where
122-
getLogLevel (l,_,_) = l
132+
instance HasHttpManager LoggingEnv where
133+
getHttpManager = lenvManager
123134

124-
instance HasHttpManager (LogLevel,Manager,Sticky) where
125-
getHttpManager (_,m,_) = m
135+
instance HasTerminal LoggingEnv where
136+
getTerminal = lenvTerminal
126137

127138
-- | Run the logging monad.
128139
runStackLoggingT :: MonadIO m
@@ -133,7 +144,12 @@ runStackLoggingT manager logLevel terminal m =
133144
(\sticky ->
134145
runReaderT
135146
(unStackLoggingT m)
136-
(logLevel, manager, sticky))
147+
LoggingEnv
148+
{ lenvLogLevel = logLevel
149+
, lenvManager = manager
150+
, lenvSticky = sticky
151+
, lenvTerminal = terminal
152+
})
137153

138154
-- | Convenience for getting a 'Manager'
139155
newTLSManager :: MonadIO m => m Manager

0 commit comments

Comments
 (0)