-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.Sem.Logger.Level where

import Imports
import qualified SAML2.WebSSO as SAML
import qualified System.Logger as Log

-- | The logging level
data Level
  = Fatal
  | Error
  | Warn
  | Info
  | Debug
  | Trace
  deriving (Level -> Level -> Bool
(Level -> Level -> Bool) -> (Level -> Level -> Bool) -> Eq Level
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Level -> Level -> Bool
== :: Level -> Level -> Bool
$c/= :: Level -> Level -> Bool
/= :: Level -> Level -> Bool
Eq, Int -> Level -> ShowS
[Level] -> ShowS
Level -> String
(Int -> Level -> ShowS)
-> (Level -> String) -> ([Level] -> ShowS) -> Show Level
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Level -> ShowS
showsPrec :: Int -> Level -> ShowS
$cshow :: Level -> String
show :: Level -> String
$cshowList :: [Level] -> ShowS
showList :: [Level] -> ShowS
Show)

toLevel :: Level -> Log.Level
toLevel :: Level -> Level
toLevel = \case
  Level
Fatal -> Level
Log.Fatal
  Level
Error -> Level
Log.Error
  Level
Warn -> Level
Log.Warn
  Level
Info -> Level
Log.Info
  Level
Debug -> Level
Log.Debug
  Level
Trace -> Level
Log.Trace

fromLevel :: Log.Level -> Level
fromLevel :: Level -> Level
fromLevel = \case
  Level
Log.Fatal -> Level
Fatal
  Level
Log.Error -> Level
Error
  Level
Log.Warn -> Level
Warn
  Level
Log.Info -> Level
Info
  Level
Log.Debug -> Level
Debug
  Level
Log.Trace -> Level
Trace

samlToLevel :: SAML.Level -> Log.Level
samlToLevel :: Level -> Level
samlToLevel = \case
  Level
SAML.Fatal -> Level
Log.Fatal
  Level
SAML.Error -> Level
Log.Error
  Level
SAML.Warn -> Level
Log.Warn
  Level
SAML.Info -> Level
Log.Info
  Level
SAML.Debug -> Level
Log.Debug
  Level
SAML.Trace -> Level
Log.Trace

samlFromLevel :: SAML.Level -> Level
samlFromLevel :: Level -> Level
samlFromLevel = \case
  Level
SAML.Fatal -> Level
Fatal
  Level
SAML.Error -> Level
Error
  Level
SAML.Warn -> Level
Warn
  Level
SAML.Info -> Level
Info
  Level
SAML.Debug -> Level
Debug
  Level
SAML.Trace -> Level
Trace