| Copyright | (c) 2018-2020 Kowainik 2021-2023 Co-Log |
|---|---|
| License | MPL-2.0 |
| Maintainer | Co-Log <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Colog.Core.Severity
Contents
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
- pattern D :: Severity
- pattern I :: Severity
- pattern W :: Severity
- pattern E :: Severity
- filterBySeverity :: 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
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
| Bounded Severity Source # | |
| Enum Severity Source # | |
Defined in Colog.Core.Severity | |
| Ix Severity Source # | |
Defined in Colog.Core.Severity Methods range :: (Severity, Severity) -> [Severity] # index :: (Severity, Severity) -> Severity -> Int # unsafeIndex :: (Severity, Severity) -> Severity -> Int # inRange :: (Severity, Severity) -> Severity -> Bool # rangeSize :: (Severity, Severity) -> Int # unsafeRangeSize :: (Severity, Severity) -> Int # | |
| Read Severity Source # | |
| Show Severity Source # | |
| Eq Severity Source # | |
| Ord Severity Source # | |
Defined in Colog.Core.Severity | |
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"
filterBySeverity :: 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 ::LogActionm (WithSeverityString) -> m () logSomething logger = logger <& "hello" `WithSeverity`Infocmap' :: (b -> a) ->LogActionm (WithSeveritya) ->LogActionm (WithSeverityb) cmap' f action =cmap(fmapf) action filterBySeverity' :: (Applicativem) =>Severity->LogActionm (WithSeveritya) ->LogActionm (WithSeveritya) filterBySeverity' threshold action =filterBySeveritythresholdgetSeverityaction
Since: 0.3.1.0
Constructors
| WithSeverity | |
Fields
| |
Instances
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 ::LogActionm (WithSeveritymsg) ->LogActionm (WithSeveritymsg) suppressErrors =cmap(mapSeverity(s -> if s ==ErrorthenWarningelse s))
Since: 0.3.1.0