Katip日志库的最小示例

时间:2017-12-24 17:34:05

标签: haskell

是否有一个最小的例子证明了Katip logging library对haskell的使用?

1 个答案:

答案 0 :(得分:2)

信用转到Joe Kachmar

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

module Main where

import Control.Exception
import Katip
import System.IO (stdout)

type Stack a = KatipContextT IO a

-- `Stack ()` is the same thing as `KatipContextT IO ()`
-- test :: Stack ()
test :: KatipContextT IO ()
test = do
  $(logTM) InfoS "Hello from Katip!"
  $(logTM) InfoS "I can do any kind of `IO` action here with `liftIO`!"

main :: IO ()
main = do
  handleScribe <- mkHandleScribe ColorIfTerminal stdout InfoS V2
  let mkLogEnv = registerScribe "stdout" handleScribe defaultScribeSettings =<< initLogEnv "MyApp" "production"

  bracket mkLogEnv closeScribes $ \le -> do
    runKatipContextT le (mempty :: LogContexts) mempty test