Giter Club home page Giter Club logo

polysemy-log's Introduction

Log thrice, debug once.

–– Г. Любенов

About

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

polysemy-log's People

Contributors

tek avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.