From ccdb5a3c6a28cc6745d337bdb67e62d70216ef7e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Apr 2017 13:54:16 -0400 Subject: refactor out Log --- debug-me.hs | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'debug-me.hs') diff --git a/debug-me.hs b/debug-me.hs index 058e23a..0b51878 100644 --- a/debug-me.hs +++ b/debug-me.hs @@ -6,7 +6,9 @@ import Types import Hash import Pty import CmdLine +import Log import Graphviz +import Replay import Control.Concurrent import Control.Concurrent.Async @@ -15,11 +17,9 @@ import System.IO import System.Process import System.Exit import qualified Data.ByteString as B -import qualified Data.ByteString.Lazy as L import Data.List import Data.List.NonEmpty (NonEmpty(..), toList) import Data.Monoid -import Data.Aeson import Data.Time.Clock.POSIX main :: IO () @@ -28,6 +28,7 @@ main = do case mode c of Test -> test Graphviz g -> graphviz g + Replay r -> replay r test :: IO () test = do @@ -214,27 +215,6 @@ user startmsg p ichan ochan = withLogger "debug-me.log" $ \logger -> do data Backlog = Backlog (NonEmpty ActivityLog) deriving (Show) -type Logger = SomeActivity -> IO () - -withLogger :: FilePath -> (Logger -> IO a) -> IO a -withLogger logfile a = withFile logfile WriteMode (a . mkLogger) - -mkLogger :: Handle -> Logger -mkLogger h a = do - l <- mkActivityLog a <$> getPOSIXTime - L.hPut h (encode l) - hPutStr h "\n" - hFlush h - -mkActivityLog :: SomeActivity -> POSIXTime -> ActivityLog -mkActivityLog a now = ActivityLog - { loggedActivity = a - , loggedHash = case a of - ActivitySeen s -> hash s - ActivityEntered e -> hash e - , loggedTimestamp = now - } - -- | Forward things written to the Pty out the TChan. sendPtyOutput :: Pty -> TChan (Activity Seen) -> TVar Backlog -> Logger -> IO () sendPtyOutput p ochan backlog logger = go -- cgit v1.2.3