diff --git a/Assistant/WebApp/Control.hs b/Assistant/WebApp/Control.hs index e6846be47d..ac6729e24f 100644 --- a/Assistant/WebApp/Control.hs +++ b/Assistant/WebApp/Control.hs @@ -11,6 +11,7 @@ module Assistant.WebApp.Control where import Assistant.WebApp.Common import Locations.UserConfig +import Utility.LogFile import Control.Concurrent import System.Posix (getProcessID, signalProcess, sigTERM) @@ -40,3 +41,10 @@ getRestartR = page "Restarting" Nothing $ do where restartcommand program = program ++ " assistant --stop; " ++ program ++ " webapp" + +getLogR :: Handler RepHtml +getLogR = page "Logs" Nothing $ do + logfile <- lift $ runAnnex undefined $ fromRepo gitAnnexLogFile + logs <- liftIO $ listLogs logfile + logcontent <- liftIO $ concat <$> mapM readFile logs + $(widgetFile "control/log") diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index 22ffbb5a53..23de3f6e4d 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -8,6 +8,7 @@ /shutdown ShutdownR GET /shutdown/confirm ShutdownConfirmedR GET /restart RestartR GET +/log LogR GET /config ConfigurationR GET /config/repository RepositoriesR GET diff --git a/Utility/LogFile.hs b/Utility/LogFile.hs index c45a1d4057..1985b7edac 100644 --- a/Utility/LogFile.hs +++ b/Utility/LogFile.hs @@ -19,7 +19,7 @@ openLog logfile = do rotateLog :: FilePath -> Int -> IO () rotateLog logfile num - | num >= 10 = return () + | num > maxLogs = return () | otherwise = whenM (doesFileExist currfile) $ do rotateLog logfile (num + 1) renameFile currfile nextfile @@ -28,4 +28,15 @@ rotateLog logfile num nextfile = filename (num + 1) filename n | n == 0 = logfile - | otherwise = logfile ++ "." ++ show n + | otherwise = rotatedLog logfile n + +rotatedLog :: FilePath -> Int -> FilePath +rotatedLog logfile n = logfile ++ "." ++ show n + +{- Lists most recent logs last. -} +listLogs :: FilePath -> IO [FilePath] +listLogs logfile = filterM doesFileExist $ reverse $ + logfile : map (rotatedLog logfile) [1..maxLogs] + +maxLogs :: Int +maxLogs = 9 diff --git a/debian/changelog b/debian/changelog index 344081fa3c..e08fc78761 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ git-annex (3.20130115) UNRELEASED; urgency=low * webapp: Avoid an error if a transfer is stopped just as it finishes. Closes: #698184 * webapp: Now always logs to .git/annex/daemon.log. + * webapp: Now has a page to view the log, accessed from the control menu. -- Joey Hess Mon, 14 Jan 2013 18:35:01 -0400 diff --git a/templates/control/log.hamlet b/templates/control/log.hamlet new file mode 100644 index 0000000000..eda88bc01d --- /dev/null +++ b/templates/control/log.hamlet @@ -0,0 +1,6 @@ +
+

+ Here's everything that has been logged by the git-annex assistant, # + as well as by programs it has run. +

+    #{logcontent}
diff --git a/templates/controlmenu.hamlet b/templates/controlmenu.hamlet
index 815d84b8c2..eda99d93e6 100644
--- a/templates/controlmenu.hamlet
+++ b/templates/controlmenu.hamlet
@@ -8,3 +8,5 @@
        Restart daemon
     
        Shutdown daemon
+    
+       View log