-
Notifications
You must be signed in to change notification settings - Fork 332
[Polysemy] Generalise and Move the Logger Effect to polysemy-wire-zoo #2306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dabaa36
Generalise the Spar.Sem.Logger effect
a01ed8d
Move the Logger effect into polysemy-wire-zoo
5e7908d
Add a changelog
607e4a0
fixup! Move the Logger effect into polysemy-wire-zoo
8855d82
fixup! Generalise the Spar.Sem.Logger effect
7b42111
Add TinyLog interpretations of Wire.Sem.Logger
0af4c71
Use the new Logger effect in Galley and Federator
df8fbed
Merge remote-tracking branch 'origin/develop' into mdimjasevic/polyse…
b4b3ae0
Drop a mistakenly introduced call to runWaiError
c3010f4
Merge remote-tracking branch 'origin/develop' into mdimjasevic/polyse…
d52a2b2
Implement loggerToTinyLogReqId via mapLogger
1c3ee86
Move discardLogs out of the TinyLog interpretation module
ef2bb10
Merge remote-tracking branch 'origin/develop' into mdimjasevic/polyse…
e1515aa
Merge remote-tracking branch 'origin/develop' into mdimjasevic/polyse…
3037d97
Hi CI
ba6f4b2
Hi CI again
149a700
Merge remote-tracking branch 'origin/develop' into mdimjasevic/polyse…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Generalise and move the Logger effect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| -- This file is part of the Wire Server implementation. | ||
| -- | ||
| -- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com> | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify it under | ||
| -- the terms of the GNU Affero General Public License as published by the Free | ||
| -- Software Foundation, either version 3 of the License, or (at your option) any | ||
| -- later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, but WITHOUT | ||
| -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| -- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
| -- details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License along | ||
| -- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| module Wire.Sem.Logger.TinyLog | ||
| ( loggerToTinyLog, | ||
| loggerToTinyLogReqId, | ||
| stringLoggerToTinyLog, | ||
| discardTinyLogs, | ||
| module Wire.Sem.Logger.Level, | ||
| ) | ||
| where | ||
|
|
||
| import Data.Id | ||
| import Imports | ||
| import Polysemy | ||
| import qualified System.Logger as Log | ||
| import Wire.Sem.Logger | ||
| import Wire.Sem.Logger.Level | ||
|
|
||
| loggerToTinyLog :: | ||
| Member (Embed IO) r => | ||
| Log.Logger -> | ||
| Sem (Logger (Log.Msg -> Log.Msg) ': r) a -> | ||
| Sem r a | ||
| loggerToTinyLog tinylog = interpret $ \case | ||
| Log lvl msg -> | ||
| embed @IO $ Log.log tinylog (toLevel lvl) msg | ||
|
|
||
| -- | Log the request ID along with the message | ||
| loggerToTinyLogReqId :: | ||
| Member (Embed IO) r => | ||
| RequestId -> | ||
| Log.Logger -> | ||
| Sem (Logger (Log.Msg -> Log.Msg) ': r) a -> | ||
| Sem r a | ||
| loggerToTinyLogReqId r tinylog = | ||
| loggerToTinyLog tinylog | ||
| . mapLogger | ||
| (Log.field "request" (unRequestId r) Log.~~) | ||
| . raise @(Logger (Log.Msg -> Log.Msg)) | ||
|
|
||
| stringLoggerToTinyLog :: Member (Logger (Log.Msg -> Log.Msg)) r => Sem (Logger String ': r) a -> Sem r a | ||
| stringLoggerToTinyLog = mapLogger @String Log.msg | ||
|
|
||
| discardTinyLogs :: Sem (Logger (Log.Msg -> Log.Msg) ': r) a -> Sem r a | ||
| discardTinyLogs = discardLogs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do you need this function?
Uh oh!
There was an error while loading. Please reload this page.
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.
This is to help GHC with type inference. If I don't use it, then GHC reports overlapping instances. An alternative is to use
discardLogs @(Log.Msg -> Log.Msg)instead ofdiscardTinyLogs.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.
That's surprising to me. Does the polysemy plugin help?
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.
It doesn't seem to. I tried this: 1) put the plugin as a GHC option in the cabal file and make its package a dependency, 2) use
discardLogsinstead ofdiscardTinyLogswhere I'm hoping the plugin would help, 3) observe I get the aforementioned error on overlapping instances, e.g.: