MyNixOS website logo
Description

A Polysemy logging effect for high quality (unstructured) logs.

co-log-polysemy-formatting builds on the co-log-polysemy package, adding terminal colours, log severity, timestamps, callers, thread ids, and a flexible log format with good defaults. It also allows you to use the formatting library for formatting your log messages.

co-log-polysemy-formatting Build Status Hackage

co-log-polysemy-formatting gives you a Polysemy logging effect for high quality (unstructured) logs.

It does this by tying together several excellent packages:

To get started, see the haddock documentation.

Output format

The output format is customisable, but by default it includes:

  • The message severity,
  • a message timestamp, with nanosecond accuracy,
  • a thread Id,
  • a source location, and
  • your log message, formatted using formatting.

example output

The colours show up if your terminal supports them, otherwise it will fall back to greyscale, including if you pipe the output to a file.

formatting messages

Our logging functions, e.g. logInfo, take a formatting formatter rather than a String/Text/etc. This makes it quick and easy to build your log messages from whatever type you have at hand, and still allows you to directly log string literals thanks to the OverloadedStrings language extension:

{-# LANGUAGE OverloadedStrings #-}

myString :: String
myString = "this is my string"

myStrictText :: Data.Text.Text
myStrictText = "this is my strict text"

myLazyText :: Data.Text.Lazy.Text
myLazyText = "this is my lazy text"

-- These will all work:
logInfo "a string literal"
logInfo string myString
logInfo stext myStrictText
logInfo text myLazyText
logInfo (string % ", " % stext % ", " % text) myString myStrictText myLazyText

-- And logging structures is easy too:
data Person = Person { personName :: Text, personAge :: Int }

myPerson :: Person
myPerson = Person "Dave" 16

logInfo ("The person's name is " % accessed personName text <> ", and their age is " % accessed personAge int) myPerson

-- Or with lenses
data Person' = Person' { _personName :: Text, _personAge :: Int }
makeLenses ''Person'

myPerson' :: Person'
myPerson' = Person' "Dave" 16

logInfo ("The person's name is " % viewed personName text <> ", and their age is " % viewed personAge int) myPerson'

Why not just use co-log-polysemy?

co-log-polysemy is a generic logging effect that leaves many decisions up to you, such as your logging format and your logging message type. But if you want something that just works, with good defaults, then co-log-polysemy-formatting will get you there faster. And you're still using co-log-polysemy under the hood -- we even re-export some of its functions for you -- we've just added a few features on top.

Metadata

Version

0.1.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows