co-log-core-0.3.2.5: Composable Contravariant Comonadic Logging Library

Copyright | (c) 2018-2020 Kowainik 2021-2025 Co-Log
License | MPL-2.0
Maintainer | Co-Log <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Colog.Core.Severity

Contents

- Patterns

Description

This module introduces `Severity` data type for expressing how severe the message is. Also, it contains useful functions and patterns for work with `Severity`.

Severity | Pattern | Meaning | Example
--- | --- | --- | ---
`Debug` | `D` | Information useful for debug purposes | Internal function call logs
`Info` | `I` | Normal operational information | Finish file uploading
`Warning` | `W` | General warnings, non-critical failures | Image load error
`Error` | `E` | General errors/severe errors | Could not connect to the DB

Synopsis

- data Severity
  - = Debug
  - | Info
  - | Warning
  - | Error
- pattern D :: Severity
- pattern I :: Severity
- pattern W :: Severity
- pattern E :: Severity
- filterBySeverity :: forall (m :: Type -> Type) a. Applicative m => Severity -> (a -> Severity) -> LogAction m a -> LogAction m a
- data WithSeverity msg = WithSeverity {
  - getMsg :: msg
  - getSeverity :: Severity
  }
- mapSeverity :: (Severity -> Severity) -> WithSeverity msg -> WithSeverity msg

# Documentation

data Severity Source #

Severity for the log messages.

Constructors

Debug | Information useful for debug purposes. E.g. output of the function that is important for the internal development, not for users. Like, the result of SQL query.
Info | Normal operational information. E.g. describing general steps: starting application, finished downloading.
Warning | General warnings, non-critical failures. E.g. couldn't download icon from some service to display.
Error | General errors/severe errors. E.g. exceptional situations: couldn't syncronize accounts.

#### Instances

Instances details

Bounded Severity Source # |
Instance details Defined in Colog.Core.Severity Methods minBound :: Severity Source # maxBound :: Severity Source #
Enum Severity Source # |

Instance details

Defined in Colog.Core.Severity

Methods

succ :: Severity -> Severity Source #

pred :: Severity -> Severity Source #

toEnum :: Int -> Severity Source #

fromEnum :: Severity -> Int Source #

enumFrom :: Severity -> [Severity] Source #

enumFromThen :: Severity -> Severity -> [Severity] Source #

enumFromTo :: Severity -> Severity -> [Severity] Source #

enumFromThenTo :: Severity -> Severity -> Severity -> [Severity] Source #

Ix Severity Source # |
Instance details Defined in Colog.Core.Severity Methods range :: (Severity, Severity) -> [Severity] Source # index :: (Severity, Severity) -> Severity -> Int Source # unsafeIndex :: (Severity, Severity) -> Severity -> Int Source # inRange :: (Severity, Severity) -> Severity -> Bool Source # rangeSize :: (Severity, Severity) -> Int Source # unsafeRangeSize :: (Severity, Severity) -> Int Source #
Read Severity Source # |
Instance details Defined in Colog.Core.Severity Methods readsPrec :: Int -> ReadS Severity Source # readList :: ReadS [Severity] Source # readPrec :: ReadPrec Severity Source # readListPrec :: ReadPrec [Severity] Source #
Show Severity Source # |
Instance details Defined in Colog.Core.Severity Methods showsPrec :: Int -> Severity -> ShowS Source # show :: Severity -> String Source # showList :: [Severity] -> ShowS Source #
Eq Severity Source # |
Instance details Defined in Colog.Core.Severity Methods (==) :: Severity -> Severity -> Bool Source # (/=) :: Severity -> Severity -> Bool Source #
Ord Severity Source # |
Instance details Defined in Colog.Core.Severity Methods compare :: Severity -> Severity -> Ordering Source # (<) :: Severity -> Severity -> Bool Source # (<=) :: Severity -> Severity -> Bool Source # (>) :: Severity -> Severity -> Bool Source # (>=) :: Severity -> Severity -> Bool Source # max :: Severity -> Severity -> Severity Source # min :: Severity -> Severity -> Severity Source #

## Patterns

Instead of using full names of the constructors you can instead use one-letter patterns. To do so you can import and use the pattern:

    import Colog (pattern D)

    example :: WithLog env Message m => m ()
    example = log D "I'm using severity pattern"

Moreover, you could use patterns when pattern-matching on severity

    errorToStderr :: Severity -> IO ()
    errorToStderr E = hputStrLn stderr "Error severity"
    errorToStderr _ = putStrLn "Something else"

pattern D :: Severity Source #

pattern I :: Severity Source #

pattern W :: Severity Source #

pattern E :: Severity Source #

filterBySeverity :: forall (m :: Type -> Type) a. Applicative m => Severity -> (a -> Severity) -> LogAction m a -> LogAction m a Source #

Filters messages by the given `Severity`.

data WithSeverity msg Source #

A message tagged with a `Severity`.

It is common to want to log various types of messages tagged with a severity. `WithSeverity` provides a standard way to do so while allowing the messages to be processed independently of the severity.

It is easy to `cmap` over a 'LogAction m (WithSeverity a)', or to filter based on the severity.

    logSomething :: LogAction m (WithSeverity String) -> m ()
    logSomething logger = logger <& "hello" `WithSeverity` Info

    cmap' :: (b -> a) -> LogAction m (WithSeverity a) -> LogAction m (WithSeverity b)
    cmap' f action = cmap (fmap f) action

    filterBySeverity' :: (Applicative m) => Severity -> LogAction m (WithSeverity a) -> LogAction m (WithSeverity a)
    filterBySeverity' threshold action = filterBySeverity threshold getSeverity action

Since: 0.3.1.0

Constructors

WithSeverity |

Fields

- getMsg :: msg
- getSeverity :: Severity

#### Instances

Instances details

Functor WithSeverity Source # |
Instance details Defined in Colog.Core.Severity Methods fmap :: (a -> b) -> WithSeverity a -> WithSeverity b Source # (<$) :: a -> WithSeverity b -> WithSeverity a Source #
Foldable WithSeverity Source # |

Instance details

Defined in Colog.Core.Severity

Methods

fold :: Monoid m => WithSeverity m -> m Source #

foldMap :: Monoid m => (a -> m) -> WithSeverity a -> m Source #

foldMap' :: Monoid m => (a -> m) -> WithSeverity a -> m Source #

foldr :: (a -> b -> b) -> b -> WithSeverity a -> b Source #

foldr' :: (a -> b -> b) -> b -> WithSeverity a -> b Source #

foldl :: (b -> a -> b) -> b -> WithSeverity a -> b Source #

foldl' :: (b -> a -> b) -> b -> WithSeverity a -> b Source #

foldr1 :: (a -> a -> a) -> WithSeverity a -> a Source #

foldl1 :: (a -> a -> a) -> WithSeverity a -> a Source #

toList :: WithSeverity a -> [a] Source #

null :: WithSeverity a -> Bool Source #

length :: WithSeverity a -> Int Source #

elem :: Eq a => a -> WithSeverity a -> Bool Source #

maximum :: Ord a => WithSeverity a -> a Source #

minimum :: Ord a => WithSeverity a -> a Source #

sum :: Num a => WithSeverity a -> a Source #

product :: Num a => WithSeverity a -> a Source #

Traversable WithSeverity Source # |
Instance details Defined in Colog.Core.Severity Methods traverse :: Applicative f => (a -> f b) -> WithSeverity a -> f (WithSeverity b) Source # sequenceA :: Applicative f => WithSeverity (f a) -> f (WithSeverity a) Source # mapM :: Monad m => (a -> m b) -> WithSeverity a -> m (WithSeverity b) Source # sequence :: Monad m => WithSeverity (m a) -> m (WithSeverity a) Source #
Show msg => Show (WithSeverity msg) Source # |
Instance details Defined in Colog.Core.Severity Methods showsPrec :: Int -> WithSeverity msg -> ShowS Source # show :: WithSeverity msg -> String Source # showList :: [WithSeverity msg] -> ShowS Source #
Eq msg => Eq (WithSeverity msg) Source # |
Instance details Defined in Colog.Core.Severity Methods (==) :: WithSeverity msg -> WithSeverity msg -> Bool Source # (/=) :: WithSeverity msg -> WithSeverity msg -> Bool Source #
Ord msg => Ord (WithSeverity msg) Source # |

Instance details

Defined in Colog.Core.Severity

Methods

compare :: WithSeverity msg -> WithSeverity msg -> Ordering Source #

(<) :: WithSeverity msg -> WithSeverity msg -> Bool Source #

(<=) :: WithSeverity msg -> WithSeverity msg -> Bool Source #

(>) :: WithSeverity msg -> WithSeverity msg -> Bool Source #

(>=) :: WithSeverity msg -> WithSeverity msg -> Bool Source #

max :: WithSeverity msg -> WithSeverity msg -> WithSeverity msg Source #

min :: WithSeverity msg -> WithSeverity msg -> WithSeverity msg Source #

mapSeverity :: (Severity -> Severity) -> WithSeverity msg -> WithSeverity msg Source #

Map the given function over the severity of a `WithSeverity`.

This can be useful to operate generically over the severity, for example:

    suppressErrors :: LogAction m (WithSeverity msg) -> LogAction m (WithSeverity msg)
    suppressErrors = cmap (mapSeverity (s -> if s == Error then Warning else s))

Since: 0.3.1.0