是否有一个最小的例子证明了Katip logging library对haskell的使用?
答案 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