Skip to content

ElaraLang/polysemy-log

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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:

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

With nix flake:

nix build
nix build '.#polysemy-log

To run all tests:

nix flake check

About

Polysemy effects for logging

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Haskell 52.5%
  • Nix 47.5%