https://github.com/tek/polysemy-log
Polysemy effects for logging
https://github.com/tek/polysemy-log
Last synced: 4 months ago
JSON representation
Polysemy effects for logging
- Host: GitHub
- URL: https://github.com/tek/polysemy-log
- Owner: tek
- Created: 2021-03-27T20:37:27.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-12-13T12:33:13.000Z (6 months ago)
- Last Synced: 2025-12-17T07:57:03.396Z (6 months ago)
- Language: Nix
- Size: 234 KB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
> Log thrice, debug once.
>
> –– Г. Любенов
# About
A common interface for the polysemy logging backend adapters.
An example program using a simple logger with a custom data type:
```haskell
import Polysemy.Conc (runConc)
import qualified Polysemy.Log as Log
import Polysemy.Log (DataLog, Log, interpretDataLogStdout, interpretLogStdoutConc)
import qualified Polysemy.Log.Effect.DataLog as DataLog
progSimple ::
Member Log r =>
Sem r ()
progSimple = do
Log.debug "debug"
Log.warn "warn"
data Message =
Message {
severity :: Text,
message :: Text
}
deriving stock (Eq, Show)
progData ::
Member (DataLog Message) r =>
Sem r ()
progData = do
DataLog.dataLog (Message "warn" "warning!")
DataLog.local (\ msg@Message{message} -> msg {message = "context: " <> message}) do
DataLog.dataLog (Message "error" "segfault!")
main :: IO ()
main =
runConc do
interpretLogStdoutConc progSimple
interpretDataLogStdout progData
```
For more documentation, please consult Hackage:
* [polysemy-log](https://hackage.haskell.org/package/polysemy-log)
* [polysemy-log-co](https://hackage.haskell.org/package/polysemy-log-co)
* [polysemy-log-di](https://hackage.haskell.org/package/polysemy-log-di)
# Building the Project
The build is defined in [nix], supporting `flake` and legacy `nix-build`.
With `nix-build`:
```bash
nix-build -A defaultPackage
nix-build -A packages.x86_64-linux.polysemy-log
```
With `nix flake`:
```
nix build
nix build '.#polysemy-log
```
To run all tests:
```bash
nix flake check
```
[nix]: https://nixos.org/manual/nix/unstable