Skip to content
Composable loggers for PureScript.
PureScript
Branch: master
Clone or download
Latest commit 148c371 Jul 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Control Update for Purescript 0.12 Jul 15, 2018
.gitignore Add logger type, and console and writer constructors Aug 13, 2016
LICENSE Add logger type, and console and writer constructors Aug 13, 2016
README.md Update for Purescript 0.12 Jul 15, 2018
bower.json Update for Purescript 0.12 Jul 15, 2018

README.md

purescript-logging

Composable loggers for PureScript.

Usage

A logger receives records and potentially performs some effects. You can create a logger from any function r -> m Unit for any r and m.

Unlike most other logging libraries, purescript-logger has no separate concepts "loggers" and "handlers". Instead, loggers can be composed into larger loggers using the Semigroup instance. Loggers can also be transformed using cmap (for transforming records) and cfilter (for filtering records). An example use case might be the following:

data Level = Debug | Info | Warning | Error
derive instance eqLevel :: Eq Level
derive instance ordLevel :: Ord Level

type Entry =
  { time   :: DateTime
  , level  :: Level
  , fields :: Map String String
  }

fileLogger :: Path -> Logger Effect Entry
fileLogger path = Logger \entry -> ?todo {- append entry to file -}

main = do
  let debugLogger      = fileLogger "debug.log"      # cfilter (\e -> e.level == Debug)
  let productionLogger = fileLogger "production.log" # cfilter (\e -> e.level /= Debug)
  let logger = debugLogger <> productionLogger

  time <- now
  log logger {time, level: Info, fields: Map.singleton "msg" "boot"}
You can’t perform that action at this time.