module Matterhorn.State.Logging
  ( startLogging
  , stopLogging
  , logSnapshot
  , getLogDestination
  )
where

import           Prelude ()
import           Matterhorn.Prelude

import           Matterhorn.Types


startLogging :: FilePath -> MH ()
startLogging :: FilePath -> MH ()
startLogging FilePath
path = do
    LogManager
mgr <- Getting LogManager ChatState LogManager -> MH LogManager
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const LogManager ChatResources)
-> ChatState -> Const LogManager ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const LogManager ChatResources)
 -> ChatState -> Const LogManager ChatState)
-> ((LogManager -> Const LogManager LogManager)
    -> ChatResources -> Const LogManager ChatResources)
-> Getting LogManager ChatState LogManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(LogManager -> Const LogManager LogManager)
-> ChatResources -> Const LogManager ChatResources
Lens' ChatResources LogManager
crLogManager)
    IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ LogManager -> FilePath -> IO ()
startLoggingToFile LogManager
mgr FilePath
path

stopLogging :: MH ()
stopLogging :: MH ()
stopLogging = do
    LogManager
mgr <- Getting LogManager ChatState LogManager -> MH LogManager
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const LogManager ChatResources)
-> ChatState -> Const LogManager ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const LogManager ChatResources)
 -> ChatState -> Const LogManager ChatState)
-> ((LogManager -> Const LogManager LogManager)
    -> ChatResources -> Const LogManager ChatResources)
-> Getting LogManager ChatState LogManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(LogManager -> Const LogManager LogManager)
-> ChatResources -> Const LogManager ChatResources
Lens' ChatResources LogManager
crLogManager)
    IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ LogManager -> IO ()
stopLoggingToFile LogManager
mgr

logSnapshot :: FilePath -> MH ()
logSnapshot :: FilePath -> MH ()
logSnapshot FilePath
path = do
    LogManager
mgr <- Getting LogManager ChatState LogManager -> MH LogManager
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const LogManager ChatResources)
-> ChatState -> Const LogManager ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const LogManager ChatResources)
 -> ChatState -> Const LogManager ChatState)
-> ((LogManager -> Const LogManager LogManager)
    -> ChatResources -> Const LogManager ChatResources)
-> Getting LogManager ChatState LogManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(LogManager -> Const LogManager LogManager)
-> ChatResources -> Const LogManager ChatResources
Lens' ChatResources LogManager
crLogManager)
    IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ LogManager -> FilePath -> IO ()
requestLogSnapshot LogManager
mgr FilePath
path

getLogDestination :: MH ()
getLogDestination :: MH ()
getLogDestination = do
    LogManager
mgr <- Getting LogManager ChatState LogManager -> MH LogManager
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const LogManager ChatResources)
-> ChatState -> Const LogManager ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const LogManager ChatResources)
 -> ChatState -> Const LogManager ChatState)
-> ((LogManager -> Const LogManager LogManager)
    -> ChatResources -> Const LogManager ChatResources)
-> Getting LogManager ChatState LogManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(LogManager -> Const LogManager LogManager)
-> ChatResources -> Const LogManager ChatResources
Lens' ChatResources LogManager
crLogManager)
    IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ LogManager -> IO ()
requestLogDestination LogManager
mgr