diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-18 13:54:16 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-18 14:04:42 -0400 |
commit | ccdb5a3c6a28cc6745d337bdb67e62d70216ef7e (patch) | |
tree | 1a63fac950bf66bba59812d8e2f6b66aa1a05c63 /debug-me.hs | |
parent | 88a9ce01d153ad609aa02084de0a93448c29cba4 (diff) | |
download | debug-me-ccdb5a3c6a28cc6745d337bdb67e62d70216ef7e.tar.gz |
refactor out Log
Diffstat (limited to 'debug-me.hs')
-rw-r--r-- | debug-me.hs | 26 |
1 files changed, 3 insertions, 23 deletions
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 |