diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-28 12:50:53 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-28 12:51:57 -0400 |
commit | e833b89e2a1a1c2acbc0eb8bed1760ef0e50f3c5 (patch) | |
tree | 6e29670d7aeb13fc81ba30a68e21813d6ecab470 /Log.hs | |
parent | d605fdc0bbed885a003a8c42c53ce3dfadf07c49 (diff) |
log to ~/.debug-me/log/
Make watcher also log and display the name of the logfile at start and
end of session.
--download still downloads to current directory because that seems less
surprising than downloading to elsewhere. Also, the user might want to
keep a copy of the local log while downloading the server log.
Diffstat (limited to 'Log.hs')
-rw-r--r-- | Log.hs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -6,11 +6,16 @@ import Types import Hash import Memory import JSON +import SessionID import Data.Char import Data.Time.Clock.POSIX import qualified Data.ByteString.Lazy as L import System.IO +import System.Posix +import System.Directory +import System.FilePath +import Control.Exception -- | One item in a log of a debug-me session. -- @@ -49,6 +54,23 @@ type Timestamp = POSIXTime type Logger = AnyMessage -> IO () +logDir :: IO FilePath +logDir = do + home <- homeDirectory <$> (getUserEntryForID =<< getEffectiveUserID) + return $ home </> ".debug-me" </> "log" + +withSessionLogger :: SessionID -> (Logger -> IO a) -> IO a +withSessionLogger sessionid a = bracket setup cleanup go + where + setup = do + dir <- logDir + createDirectoryIfMissing True dir + let logfile = sessionLogFile dir sessionid + putStrLn $ "** debug-me is logging to " ++ logfile + return logfile + cleanup logfile = putStrLn $ "** debug-me session was logged to " ++ logfile + go logfile = withFile logfile WriteMode (a . mkLogger) + withLogger :: FilePath -> (Logger -> IO a) -> IO a withLogger logfile a = withFile logfile WriteMode (a . mkLogger) |