From 1bda1faf65c2ccf4e6a0dc349ddbc0f97b67b1da Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 30 Apr 2017 12:54:50 -0400 Subject: log remote logs to subdir --- Log.hs | 7 ++++--- Role/Developer.hs | 2 +- Role/User.hs | 3 ++- Role/Watcher.hs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Log.hs b/Log.hs index 7e414a1..6f6ce30 100644 --- a/Log.hs +++ b/Log.hs @@ -57,11 +57,12 @@ type Logger = AnyMessage -> IO () logDir :: IO FilePath logDir = ( "log") <$> dotDir -withSessionLogger :: SessionID -> (Logger -> IO a) -> IO a -withSessionLogger sessionid a = bracket setup cleanup go +withSessionLogger :: (Maybe FilePath) -> SessionID -> (Logger -> IO a) -> IO a +withSessionLogger subdir sessionid a = bracket setup cleanup go where setup = do - dir <- logDir + basedir <- logDir + let dir = maybe basedir (basedir ) subdir createDirectoryIfMissing False dir return $ sessionLogFile dir sessionid cleanup logfile = putStrLn $ "** debug-me session was logged to " ++ logfile diff --git a/Role/Developer.hs b/Role/Developer.hs index d210e50..36cc600 100644 --- a/Role/Developer.hs +++ b/Role/Developer.hs @@ -51,7 +51,7 @@ run' runner url = do void $ runClientApp app developer :: TMVar (TVar DeveloperState) -> TMChan (Message Entered) -> TMChan AnyMessage -> SessionID -> IO () -developer dsv ichan ochan sid = withSessionLogger sid $ \logger -> do +developer dsv ichan ochan sid = withSessionLogger (Just "remote") sid $ \logger -> do sk <- genMySessionKey (controlinput, controloutput) <- openControlWindow displayInControlWindow controlinput diff --git a/Role/User.hs b/Role/User.hs index d11c235..1e842d0 100644 --- a/Role/User.hs +++ b/Role/User.hs @@ -44,7 +44,8 @@ run os = fromMaybe (ExitFailure 101) <$> connect putStrLn "Others can connect to this session and help you debug by running:" putStrLn $ " debug-me " ++ show url hFlush stdout - withSessionLogger sid $ go ochan ichan usv controlinput controloutput + withSessionLogger Nothing sid $ + go ochan ichan usv controlinput controloutput go ochan ichan usv controlinput controloutput logger = do (cmd, cmdparams) <- shellCommand os runWithPty cmd cmdparams $ \(p, ph) -> do diff --git a/Role/Watcher.hs b/Role/Watcher.hs index f314b46..0867da1 100644 --- a/Role/Watcher.hs +++ b/Role/Watcher.hs @@ -15,7 +15,7 @@ run :: WatchOpts -> IO () run = run' watcher . watchUrl watcher :: TMVar (TVar DeveloperState) -> TMChan (Message Entered) -> TMChan AnyMessage -> SessionID -> IO () -watcher dsv _ichan ochan sid = withSessionLogger sid $ \logger -> inRawMode $ do +watcher dsv _ichan ochan sid = withSessionLogger (Just "remote") sid $ \logger -> inRawMode $ do sk <- genMySessionKey (st, startoutput) <- processSessionStart sk ochan logger dsv emitOutput startoutput -- cgit v1.2.3