-
Notifications
You must be signed in to change notification settings - Fork 8
[CORE-7914] Log an unhandled exception or a user abort before the computation ends #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
366add1
ab30e99
e9c4bb4
33b5d3d
60cd442
d7d8cc2
c75ec4f
ff00dce
cf22190
11a85b4
c8f1072
d93c066
dacd3a5
b0f8384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import Control.Monad.State.Class | |
| import Control.Monad.Trans.Control | ||
| import Control.Monad.Writer.Class | ||
| import Data.Aeson | ||
| import Data.Text (Text) | ||
| import Data.Text (Text, pack) | ||
| import Data.Time | ||
| import qualified Control.Monad.Fail as MF | ||
| import qualified Control.Exception as E | ||
|
|
@@ -46,26 +46,35 @@ instance MonadReader r m => MonadReader r (LogT m) where | |
| ask = lift ask | ||
| local = mapLogT . local | ||
|
|
||
| -- | Run a 'LogT' computation. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove the haddock?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I'm stupid 😬 |
||
| -- | ||
| -- Note that in the case of asynchronous/bulk loggers 'runLogT' | ||
| -- doesn't guarantee that all messages are actually written to the log | ||
| -- once it finishes. Use 'withPGLogger' or 'withElasticSearchLogger' | ||
| -- for that. | ||
| runLogT :: Text -- ^ Application component name to use. | ||
| runLogT :: (MonadMask m, MonadBase IO m) | ||
| => Text -- ^ Application component name to use. | ||
| -> Logger -- ^ The logging back-end to use. | ||
| -> LogLevel -- ^ The maximum log level allowed to be logged. | ||
| -- Only messages less or equal than this level with be logged. | ||
| -> LogT m a -- ^ The 'LogT' computation to run. | ||
| -> m a | ||
| runLogT component logger maxLogLevel m = runReaderT (unLogT m) LoggerEnv { | ||
| leLogger = logger | ||
| , leComponent = component | ||
| , leDomain = [] | ||
| , leData = [] | ||
| , leMaxLogLevel = maxLogLevel | ||
| } -- We can't do synchronisation here, since 'runLogT' can be invoked | ||
| -- quite often from the application (e.g. on every request). | ||
| runLogT component logger maxLogLevel m = | ||
| fst <$> runReaderT | ||
| (unLogT $ | ||
| generalBracket | ||
| (pure ()) | ||
| (\_ -> \case | ||
| ExitCaseSuccess _ -> pure () | ||
| ExitCaseException (SomeException e) -> do | ||
| logAttention "Uncaught exception raised" $ object ["error" .= (pack . show $ e)] | ||
| throwM e | ||
| ExitCaseAbort -> | ||
| logAttention_ "Process was aborted manually" | ||
|
||
| ) | ||
| (const m)) | ||
| LoggerEnv | ||
| { leLogger = logger | ||
| , leComponent = component | ||
| , leDomain = [] | ||
| , leData = [] | ||
| , leMaxLogLevel = maxLogLevel | ||
| } -- We can't do synchronisation here, since 'runLogT' can be invoked | ||
| -- quite often from the application (e.g. on every request). | ||
|
|
||
| -- | Transform the computation inside a 'LogT'. | ||
| mapLogT :: (m a -> n b) -> LogT m a -> LogT n b | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need pack, aeson handles string conversions itself.