on eddf78a help sign in
50 lines 1.6 kB history raw
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE RankNTypes #-}
5-- | This is a compatibility module that abstracts over the
6-- concrete choice of logging framework so users can plug in whatever
7-- framework they want to.
8module Development.IDE.Types.Logger
9 ( Priority(..)
10 , Logger(..)
11 , logError, logWarning, logInfo, logDebug
12 , noLogging
13 ) where
15import qualified Data.Text as T
18data Priority
19-- Don't change the ordering of this type or you will mess up the Ord
20-- instance
21 = Debug -- ^ Verbose debug logging.
22 | Info -- ^ Useful information in case an error has to be understood.
23 | Warning
24 -- ^ These error messages should not occur in a expected usage, and
25 -- should be investigated.
26 | Error -- ^ Such log messages must never occur in expected usage.
27 deriving (Eq, Show, Ord, Enum, Bounded)
30-- | Note that this is logging actions _of the program_, not of the user.
31-- You shouldn't call warning/error if the user has caused an error, only
32-- if our code has gone wrong and is itself erroneous (e.g. we threw an exception).
33data Logger = Logger {logPriority :: Priority -> T.Text -> IO ()}
36logError :: Logger -> T.Text -> IO ()
37logError x = logPriority x Error
39logWarning :: Logger -> T.Text -> IO ()
40logWarning x = logPriority x Warning
42logInfo :: Logger -> T.Text -> IO ()
43logInfo x = logPriority x Info
45logDebug :: Logger -> T.Text -> IO ()
46logDebug x = logPriority x Debug
49noLogging :: Logger
50noLogging = Logger $ \_ _ -> return ()