packages feed

yet-another-logger-0.2: example/Example.hs

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UnicodeSyntax #-}

-- |
-- Module: Example
-- Copyright: Copyright © 2015 PivotCloud, Inc.
-- License: Apache-2.0
-- Maintainer: Lars Kuhtz <lkuhtz@pivotmail.com>
-- Stability: experimental
--
module Main
( main
) where

import Distribution.Simple.Utils (withTempFile)

import System.IO
import System.Logger

main ∷ IO ()
main = do

    -- log to console
    withConsoleLogger Info $ withLabel ("logger", "console") run

    -- log to a file
    withTempFile "." "logfile.log" $ \f h → do
        hClose h
        withFileLogger f Info $ withLabel ("logger", "file") run
        readFile f >>= putStrLn

  where
    f = withLevel Debug $ logg Debug "debug f"

    run = do
        logg Info "moin"
        withLabel ("function", "f") f
        logg Debug "don't show this"
        logg Info "tschüss"