HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleco-log-core-0.3.2.2Haskell2010

Colog.Core.Severity

SPDX-License-Identifier : MPL-2.0 Maintainer : Co-Log xrom.xkov@gmail.com Stability : Stable Portability : Portable

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

  • 2 types
  • 2 values
datadata Severity
#

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.

Instances7Bounded, Enum, Eq, Ord, Read, Show, …
  • Bounded SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Enum SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Eq SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Ord SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Read SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Show SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity
  • Ix SeverityDefined in co-log-core-0.3.2.2 · Colog.Core.Severity

Patterns

7 declarations

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"
datadata WithSeverity msg
#

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
Instances6Functor, Foldable, Traversable, Eq, Ord, Show