-
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 10 commits
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| cabal-version: 3.0 | ||
| name: log-base | ||
| version: 0.12.0.1 | ||
| version: 0.13.0.0 | ||
|
||
| synopsis: Structured logging solution (base package) | ||
|
|
||
| description: A library that provides a way to record structured log | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ module Log.Monad ( | |
| , runLogT | ||
| , mapLogT | ||
| , logMessageIO | ||
| , logExceptions | ||
|
||
| , getLoggerIO | ||
| ) where | ||
|
|
||
|
|
@@ -67,6 +68,25 @@ runLogT component logger maxLogLevel m = runReaderT (unLogT m) LoggerEnv { | |
| } -- We can't do synchronisation here, since 'runLogT' can be invoked | ||
| -- quite often from the application (e.g. on every request). | ||
|
|
||
| -- | Unsure uncaught exceptions get logged | ||
|
||
| -- Convenient to compose right after `runLogT` so any exception | ||
| -- will show up. | ||
| logExceptions :: (MonadBaseControl IO m, MonadLog m) => m a -> m a | ||
| logExceptions f = | ||
| liftedCatch f $ \(SomeException e) -> do | ||
| logAttention "Uncaught exception" $ object ["error" .= show e] | ||
| liftBase $ E.throwIO e | ||
|
|
||
| -- Generalized version of catch taken from `lifted-base` | ||
| liftedCatch :: (MonadBaseControl IO m, Exception e) | ||
| => m a -- ^ The computation to run | ||
| -> (e -> m a) -- ^ Handler to invoke if an exception is raised | ||
| -> m a | ||
| liftedCatch a handler = control $ \runInIO -> | ||
| E.catch | ||
| (runInIO a) | ||
| (runInIO . handler) | ||
|
|
||
| -- | Transform the computation inside a 'LogT'. | ||
| mapLogT :: (m a -> n b) -> LogT m a -> LogT n b | ||
| mapLogT f = LogT . mapReaderT f . unLogT | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ library | |
| deepseq, | ||
| http-client, | ||
| http-types, | ||
| log-base >= 0.10 && <0.13, | ||
| log-base >= 0.10 && <0.14, | ||
|
||
| network-uri, | ||
| semigroups, | ||
| text, | ||
|
|
||
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.
I'll set the date when a release is made.