\subsection{Cardano.BM.Data.Severity}
\label{code:Cardano.BM.Data.Severity}

%if style == newcode
\begin{code}
{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE LambdaCase         #-}

module Cardano.BM.Data.Severity
  ( Severity (..)
  )
  where

import           Data.Aeson (FromJSON (..), ToJSON)
import           Data.Yaml (withText)

import           GHC.Generics (Generic)

\end{code}
%endif

\subsubsection{Severity}\label{code:Severity}\index{Severity}\index{Severity!instance of FromJSON}
\label{code:Debug}\index{Severity!Debug}
\label{code:Info}\index{Severity!Info}
\label{code:Notice}\index{Severity!Notice}
\label{code:Warning}\index{Severity!Warning}
\label{code:Error}\index{Severity!Error}
\label{code:Critical}\index{Severity!Critical}
\label{code:Alert}\index{Severity!Alert}
\label{code:Emergency}\index{Severity!Emergency}
The intended meaning of severity codes:

Debug     | detailed information about values and decision flow
Info      | general information of events; progressing properly
Notice    | needs attention; something not progressing properly
Warning   | may continue into an error condition if continued
Error     | unexpected set of event or condition occurred
Critical  | error condition causing degrade of operation
Alert     | a subsystem is no longer operating correctly, likely requires manual intervention
Emergency | at this point, the system can never progress without additional intervention

We were informed by the |Syslog| taxonomy: \url{https://en.wikipedia.org/wiki/Syslog#Severity_level}

\begin{code}
data Severity = Debug
              | Info
              | Notice
              | Warning
              | Error
              | Critical
              | Alert
              | Emergency
                deriving (Int -> Severity -> ShowS
[Severity] -> ShowS
Severity -> String
(Int -> Severity -> ShowS)
-> (Severity -> String) -> ([Severity] -> ShowS) -> Show Severity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Severity] -> ShowS
$cshowList :: [Severity] -> ShowS
show :: Severity -> String
$cshow :: Severity -> String
showsPrec :: Int -> Severity -> ShowS
$cshowsPrec :: Int -> Severity -> ShowS
Show, Severity -> Severity -> Bool
(Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool) -> Eq Severity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Severity -> Severity -> Bool
$c/= :: Severity -> Severity -> Bool
== :: Severity -> Severity -> Bool
$c== :: Severity -> Severity -> Bool
Eq, Eq Severity
Eq Severity
-> (Severity -> Severity -> Ordering)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Severity)
-> (Severity -> Severity -> Severity)
-> Ord Severity
Severity -> Severity -> Bool
Severity -> Severity -> Ordering
Severity -> Severity -> Severity
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Severity -> Severity -> Severity
$cmin :: Severity -> Severity -> Severity
max :: Severity -> Severity -> Severity
$cmax :: Severity -> Severity -> Severity
>= :: Severity -> Severity -> Bool
$c>= :: Severity -> Severity -> Bool
> :: Severity -> Severity -> Bool
$c> :: Severity -> Severity -> Bool
<= :: Severity -> Severity -> Bool
$c<= :: Severity -> Severity -> Bool
< :: Severity -> Severity -> Bool
$c< :: Severity -> Severity -> Bool
compare :: Severity -> Severity -> Ordering
$ccompare :: Severity -> Severity -> Ordering
$cp1Ord :: Eq Severity
Ord, Severity
Severity -> Severity -> Bounded Severity
forall a. a -> a -> Bounded a
maxBound :: Severity
$cmaxBound :: Severity
minBound :: Severity
$cminBound :: Severity
Bounded, Int -> Severity
Severity -> Int
Severity -> [Severity]
Severity -> Severity
Severity -> Severity -> [Severity]
Severity -> Severity -> Severity -> [Severity]
(Severity -> Severity)
-> (Severity -> Severity)
-> (Int -> Severity)
-> (Severity -> Int)
-> (Severity -> [Severity])
-> (Severity -> Severity -> [Severity])
-> (Severity -> Severity -> [Severity])
-> (Severity -> Severity -> Severity -> [Severity])
-> Enum Severity
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Severity -> Severity -> Severity -> [Severity]
$cenumFromThenTo :: Severity -> Severity -> Severity -> [Severity]
enumFromTo :: Severity -> Severity -> [Severity]
$cenumFromTo :: Severity -> Severity -> [Severity]
enumFromThen :: Severity -> Severity -> [Severity]
$cenumFromThen :: Severity -> Severity -> [Severity]
enumFrom :: Severity -> [Severity]
$cenumFrom :: Severity -> [Severity]
fromEnum :: Severity -> Int
$cfromEnum :: Severity -> Int
toEnum :: Int -> Severity
$ctoEnum :: Int -> Severity
pred :: Severity -> Severity
$cpred :: Severity -> Severity
succ :: Severity -> Severity
$csucc :: Severity -> Severity
Enum, (forall x. Severity -> Rep Severity x)
-> (forall x. Rep Severity x -> Severity) -> Generic Severity
forall x. Rep Severity x -> Severity
forall x. Severity -> Rep Severity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Severity x -> Severity
$cfrom :: forall x. Severity -> Rep Severity x
Generic, [Severity] -> Encoding
[Severity] -> Value
Severity -> Encoding
Severity -> Value
(Severity -> Value)
-> (Severity -> Encoding)
-> ([Severity] -> Value)
-> ([Severity] -> Encoding)
-> ToJSON Severity
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Severity] -> Encoding
$ctoEncodingList :: [Severity] -> Encoding
toJSONList :: [Severity] -> Value
$ctoJSONList :: [Severity] -> Value
toEncoding :: Severity -> Encoding
$ctoEncoding :: Severity -> Encoding
toJSON :: Severity -> Value
$ctoJSON :: Severity -> Value
ToJSON, ReadPrec [Severity]
ReadPrec Severity
Int -> ReadS Severity
ReadS [Severity]
(Int -> ReadS Severity)
-> ReadS [Severity]
-> ReadPrec Severity
-> ReadPrec [Severity]
-> Read Severity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Severity]
$creadListPrec :: ReadPrec [Severity]
readPrec :: ReadPrec Severity
$creadPrec :: ReadPrec Severity
readList :: ReadS [Severity]
$creadList :: ReadS [Severity]
readsPrec :: Int -> ReadS Severity
$creadsPrec :: Int -> ReadS Severity
Read)

\end{code}

|Severity| is a \href{https://www.wikiwand.com/en/Semilattice}{lower
semilattice}, and thus a monoid:
\begin{code}
instance Semigroup Severity where
  Severity
Debug     <> :: Severity -> Severity -> Severity
<> Severity
_         = Severity
Debug
  Severity
_         <> Severity
Debug     = Severity
Debug
  Severity
Info      <> Severity
_         = Severity
Info
  Severity
_         <> Severity
Info      = Severity
Info
  Severity
Notice    <> Severity
_         = Severity
Notice
  Severity
_         <> Severity
Notice    = Severity
Notice
  Severity
Warning   <> Severity
_         = Severity
Warning
  Severity
_         <> Severity
Warning   = Severity
Warning
  Severity
Error     <> Severity
_         = Severity
Error
  Severity
_         <> Severity
Error     = Severity
Error
  Severity
Critical  <> Severity
_         = Severity
Critical
  Severity
_         <> Severity
Critical  = Severity
Critical
  Severity
Alert     <> Severity
_         = Severity
Alert
  Severity
_         <> Severity
Alert     = Severity
Alert
  Severity
Emergency <> Severity
Emergency = Severity
Emergency

instance Monoid Severity where
  mempty :: Severity
mempty = Severity
Emergency

instance FromJSON Severity where
    parseJSON :: Value -> Parser Severity
parseJSON = String -> (Text -> Parser Severity) -> Value -> Parser Severity
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"severity" ((Text -> Parser Severity) -> Value -> Parser Severity)
-> (Text -> Parser Severity) -> Value -> Parser Severity
forall a b. (a -> b) -> a -> b
$ \case
                    Text
"Debug"     -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Debug
                    Text
"Info"      -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Info
                    Text
"Notice"    -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Notice
                    Text
"Warning"   -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Warning
                    Text
"Error"     -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Error
                    Text
"Critical"  -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Critical
                    Text
"Alert"     -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Alert
                    Text
"Emergency" -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Emergency
                    Text
_           -> Severity -> Parser Severity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
Info   -- catch all

\end{code}