Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace FoldCase by IsText and use simple case folding #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/System/Logger/Backend/ColorOption.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ module System.Logger.Backend.ColorOption
import Configuration.Utils

import Control.DeepSeq
import Control.Lens
import Control.Monad.Except

import qualified Data.CaseInsensitive as CI
import Data.Char (toLower)
#if ! MIN_VERSION_base(4,8,0)
import Data.Monoid
#endif
import Data.Monoid.Unicode
import Data.String
import qualified Data.Text as T
import Data.Text.Lens
import Data.Typeable

import GHC.Generics
Expand All @@ -85,10 +87,10 @@ data ColorOption
instance NFData ColorOption

readColorOption
∷ (Monad m, Eq a, Show a, CI.FoldCase a, IsString a, IsString e, Monoid e, MonadError e m)
∷ (Monad m, Eq a, Show a, IsText a, IsString a, IsString e, Monoid e, MonadError e m)
⇒ a
→ m ColorOption
readColorOption x = case CI.mk x of
readColorOption x = case runIdentity (text (pure . toLower) x) of
"auto" → return ColorAuto
"false" → return ColorFalse
"true" → return ColorTrue
Expand Down
13 changes: 7 additions & 6 deletions src/System/Logger/Backend/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Control.Monad.Except
import Control.Monad.Trans.Control
import Control.Monad.Writer

import qualified Data.CaseInsensitive as CI
import Data.Char (toLower)
import qualified Data.List as L
import Data.Monoid.Unicode
import Data.String
Expand Down Expand Up @@ -106,17 +106,18 @@ data LoggerHandleConfig
instance NFData LoggerHandleConfig

readLoggerHandleConfig
∷ (MonadError e m, Eq a, Show a, CI.FoldCase a, IsText a, IsString e, Monoid e)
∷ (MonadError e m, Eq a, Show a, IsText a, IsString e, Monoid e)
⇒ a
→ m LoggerHandleConfig
readLoggerHandleConfig x = case CI.mk tx of
readLoggerHandleConfig x = case foldedTx of
"stdout" → return StdOut
"stderr" → return StdErr
_ | CI.mk (L.take 5 tx) ≡ "file:" → return $ FileHandle (L.drop 5 tx)
_ | L.take 5 foldedTx ≡ "file:" → return $ FileHandle (L.drop 5 tx)
e → throwError $ "unexpected logger handle value: "
⊕ fromString (show e)
⊕ ", expected \"stdout\", \"stderr\", or \"file:<FILENAME>\""
where
foldedTx = runIdentity $ text (pure . toLower) tx
tx = packed # x

loggerHandleConfigText
Expand Down Expand Up @@ -217,7 +218,7 @@ withHandleBackend = withHandleBackend_ id

withHandleBackend_
∷ (MonadIO m, MonadBaseControl IO m)
⇒ (msg -> T.Text)
⇒ (msg T.Text)
-- ^ formatting function for the log message
→ HandleBackendConfig
→ (LoggerBackend msg → m α)
Expand All @@ -241,7 +242,7 @@ handleBackend = handleBackend_ id
{-# INLINE handleBackend #-}

handleBackend_
∷ (msg -> T.Text)
∷ (msg T.Text)
-- ^ formatting function for the log message
→ Handle
→ Bool
Expand Down
11 changes: 6 additions & 5 deletions src/System/Logger/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ import Control.Monad.Trans.Trace
import Control.Monad.Writer
import Control.Monad.Unicode

import qualified Data.CaseInsensitive as CI
import Data.Char (toLower)
import Data.Monoid.Unicode
import Data.String
import qualified Data.Text as T
Expand Down Expand Up @@ -135,10 +135,10 @@ data LogLevel
instance NFData LogLevel

readLogLevel
∷ (MonadError e m, Eq a, Show a, CI.FoldCase a, IsString a, IsString e, Monoid e)
∷ (MonadError e m, Eq a, Show a, IsText a, IsString a, IsString e, Monoid e)
⇒ a
→ m LogLevel
readLogLevel x = case CI.mk x of
readLogLevel x = case runIdentity (text (pure . toLower) x) of
"quiet" → return Quiet
"error" → return Error
"warn" → return Warn
Expand Down Expand Up @@ -196,17 +196,18 @@ logPolicyText LogPolicyRaise = "raise"
logPolicyText LogPolicyBlock = "block"

readLogPolicy
∷ (MonadError e m, Eq a, Show a, CI.FoldCase a, IsText a, IsString e, Monoid e)
∷ (MonadError e m, Eq a, Show a, IsText a, IsString e, Monoid e)
⇒ a
→ m LogPolicy
readLogPolicy x = case CI.mk tx of
readLogPolicy x = case foldedTx of
"discard" → return LogPolicyDiscard
"raise" → return LogPolicyRaise
"block" → return LogPolicyBlock
e → throwError
$ "invalid log policy value " ⊕ fromString (show e) ⊕ ";"
⊕ " the log policy value must be one of \"discard\", \"raise\", or \"block\""
where
foldedTx = runIdentity $ text (pure . toLower) tx
tx = packed # x

instance ToJSON LogPolicy where
Expand Down
1 change: 0 additions & 1 deletion yet-another-logger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ Library
base == 4.*,
base-unicode-symbols >= 0.2,
bytestring >= 0.10,
case-insensitive >= 1.2,
clock >= 0.4,
configuration-tools >= 0.2.8,
deepseq >= 1.3,
Expand Down