polysemy-log: Polysemy Effects for Logging

[ library, logging ] [ Propose Tags ]

See https://hackage.haskell.org/package/polysemy-log/docs/Polysemy-Log.html

[Skip to Readme]
Versions [RSS] [faq],,,,,,,,,,,,,, (info)
Change log changelog.md
Dependencies ansi-terminal (>=0.10.3), async, base (==4.*), polysemy (>=1.5), polysemy-conc (>=0.3), polysemy-time (>=0.1.4), relude (>=0.7), template-haskell, text, time [details]
License BSD-2-Clause-Patent
Copyright 2021 Torsten Schmits
Author Torsten Schmits
Maintainer tek@tryp.io
Category Logging
Home page https://github.com/tek/polysemy-log#readme
Bug tracker https://github.com/tek/polysemy-log/issues
Source repo head: git clone https://github.com/tek/polysemy-log
Uploaded by tek at 2021-12-21T20:35:53Z
Distributions NixOS:
Downloads 1415 total (57 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees


Readme for polysemy-log-

[back to package description]

Log thrice, debug once.

–– Г. Любенов


A common interface for the polysemy logging backend adapters.

An example program using a simple logger with predefined formatting and a custom data type:

import Colog (logTextStdout)
import Colog.Polysemy (runLogAction)
import Polysemy (runM)

import Polysemy.Log.Colog (interpretDataLogColog, interpretLogStdout)
import qualified Polysemy.Log.Data.DataLog as DataLog
import Polysemy.Log.Data.DataLog (DataLog)
import qualified Polysemy.Log.Data.Log as Log
import Polysemy.Log.Data.Log (Log)

progSimple ::
  Member Log r =>
  Sem r ()
progSimple = do
  Log.debug "debug"
  Log.warn "warn"

data Message =
  Message {
    severity :: Text,
    message :: Text
  deriving (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 =
  runM do
    interpretLogStdout progSimple
    runLogAction @IO (contramap message logTextStdout) $ interpretDataLogColog @Message $ progData

For more documentation, please consult Hackage:

Building the Project

The build is defined in nix, supporting flake and legacy nix-build.

With nix-build:

nix-build -A defaultPackage
nix-build -A packages.x86_64-linux.polysemy-log-co

With nix flake:

nix build
nix build '.#polysemy-log-co'

To run all tests:

nix flake check