packages feed

uniform-error-0.1.5.2: Uniform/NoticeLevel.hs

----------------------------------------------------------------------
--
-- Module      :  Uniform.NoticeLevel
--              a simplistic idea to control the amount of output 
--              helping with debug 
--
----------------------------------------------------------------------

    -- {-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- {-# LANGUAGE PackageImports #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveDataTypeable #-}

{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
-- runErrorT is depreceiated but used in monads-tf
{-# OPTIONS_GHC -w #-}

module  Uniform.NoticeLevel
  ( module Uniform.NoticeLevel
      )
where

 
import Uniform.Strings hiding (S, (<.>), (</>))
import Data.Default
import GHC.Generics
import Control.Monad.IO.Class (liftIO, MonadIO)
import Control.Monad (when)
import Data.Data 

-- | increasing noticeLevels produce more output
data NoticeLevel = NoticeLevel0 | NoticeLevel1 | NoticeLevel2 deriving (Eq, Ord, Show, Read, Generic, Data)
instance Zeros NoticeLevel where zero = NoticeLevel0 
instance Default NoticeLevel where 
        def = NoticeLevel2 

inform, informNone, informAll, informOne:: NoticeLevel -> Bool
inform =  not . isZero
informNone = const False  -- to use with: when (informNone debug)
informAll = const True 
informOne debug = debug > NoticeLevel0 
informTwo debug = debug > NoticeLevel1 
-- should only print most important messages

putInform :: MonadIO m => NoticeLevel -> [Text] -> m () 
-- produce output if debug > NoticeLevel0 
putInform debug texts = when  (inform debug)  $ 
        putIOwords texts

putInformZero :: MonadIO m => NoticeLevel -> [Text] -> m () 
-- produce always output 
putInformZero debug texts =  putIOwords texts

putInformOne :: MonadIO m => NoticeLevel -> [Text] -> m () 
-- produce output if debug > NoticeLevel0 
putInformOne debug texts = when  (informOne debug)  $ 
        putIOwords texts

putInformTwo :: MonadIO m => NoticeLevel -> [Text] -> m () 
-- produce output if debug > NoticeLevel1 
putInformTwo debug texts = when  (informTwo debug)  $ 
        putIOwords texts