{- | Provides an implementation of the ghcide @Logger@ which uses
   @System.Log.Logger@ under the hood.
-}
module Ide.Logger
  (
    hlsLogger
  , logm
  , debugm
  , warningm
  , errorm
  ) where

import           Control.Monad.IO.Class
import qualified Data.Text as T
import qualified Development.IDE.Types.Logger as L
import           System.Log.Logger

-- ---------------------------------------------------------------------


hlsLogger :: L.Logger
hlsLogger :: Logger
hlsLogger = (Priority -> Text -> IO ()) -> Logger
L.Logger ((Priority -> Text -> IO ()) -> Logger)
-> (Priority -> Text -> IO ()) -> Logger
forall a b. (a -> b) -> a -> b
$ \Priority
pri Text
txt ->
    case Priority
pri of
      Priority
L.Telemetry -> String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
logm     (Text -> String
T.unpack Text
txt)
      Priority
L.Debug     -> String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
debugm   (Text -> String
T.unpack Text
txt)
      Priority
L.Info      -> String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
logm     (Text -> String
T.unpack Text
txt)
      Priority
L.Warning   -> String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
warningm (Text -> String
T.unpack Text
txt)
      Priority
L.Error     -> String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
errorm   (Text -> String
T.unpack Text
txt)

-- ---------------------------------------------------------------------


logm :: MonadIO m => String -> m ()
logm :: String -> m ()
logm String
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
infoM String
"hls" String
s

debugm :: MonadIO m => String -> m ()
debugm :: String -> m ()
debugm String
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
debugM String
"hls" String
s

warningm :: MonadIO m => String -> m ()
warningm :: String -> m ()
warningm String
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
warningM String
"hls" String
s

errorm :: MonadIO m => String -> m ()
errorm :: String -> m ()
errorm String
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
errorM String
"hls" String
s

-- ---------------------------------------------------------------------