webapp: Now has a page to view the log, accessed from the control menu.

This commit is contained in:
Joey Hess 2013-01-15 13:52:35 -04:00
parent d7ca6fb856
commit e15cca7db8
6 changed files with 31 additions and 2 deletions

View file

@ -11,6 +11,7 @@ module Assistant.WebApp.Control where
import Assistant.WebApp.Common import Assistant.WebApp.Common
import Locations.UserConfig import Locations.UserConfig
import Utility.LogFile
import Control.Concurrent import Control.Concurrent
import System.Posix (getProcessID, signalProcess, sigTERM) import System.Posix (getProcessID, signalProcess, sigTERM)
@ -40,3 +41,10 @@ getRestartR = page "Restarting" Nothing $ do
where where
restartcommand program = program ++ " assistant --stop; " ++ restartcommand program = program ++ " assistant --stop; " ++
program ++ " webapp" 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")

View file

@ -8,6 +8,7 @@
/shutdown ShutdownR GET /shutdown ShutdownR GET
/shutdown/confirm ShutdownConfirmedR GET /shutdown/confirm ShutdownConfirmedR GET
/restart RestartR GET /restart RestartR GET
/log LogR GET
/config ConfigurationR GET /config ConfigurationR GET
/config/repository RepositoriesR GET /config/repository RepositoriesR GET

View file

@ -19,7 +19,7 @@ openLog logfile = do
rotateLog :: FilePath -> Int -> IO () rotateLog :: FilePath -> Int -> IO ()
rotateLog logfile num rotateLog logfile num
| num >= 10 = return () | num > maxLogs = return ()
| otherwise = whenM (doesFileExist currfile) $ do | otherwise = whenM (doesFileExist currfile) $ do
rotateLog logfile (num + 1) rotateLog logfile (num + 1)
renameFile currfile nextfile renameFile currfile nextfile
@ -28,4 +28,15 @@ rotateLog logfile num
nextfile = filename (num + 1) nextfile = filename (num + 1)
filename n filename n
| n == 0 = logfile | 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

1
debian/changelog vendored
View file

@ -5,6 +5,7 @@ git-annex (3.20130115) UNRELEASED; urgency=low
* webapp: Avoid an error if a transfer is stopped just as it finishes. * webapp: Avoid an error if a transfer is stopped just as it finishes.
Closes: #698184 Closes: #698184
* webapp: Now always logs to .git/annex/daemon.log. * 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 <joeyh@debian.org> Mon, 14 Jan 2013 18:35:01 -0400 -- Joey Hess <joeyh@debian.org> Mon, 14 Jan 2013 18:35:01 -0400

View file

@ -0,0 +1,6 @@
<div .span9 .hero-unit>
<p>
Here's everything that has been logged by the git-annex assistant, #
as well as by programs it has run.
<pre>
#{logcontent}

View file

@ -8,3 +8,5 @@
<i .icon-repeat></i> Restart daemon <i .icon-repeat></i> Restart daemon
<a href="@{ShutdownR}"> <a href="@{ShutdownR}">
<i .icon-off></i> Shutdown daemon <i .icon-off></i> Shutdown daemon
<a href="@{LogR}">
<i .icon-list></i> View log