aboutsummaryrefslogtreecommitdiff
path: root/Utility/LogFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-01-15 13:52:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-01-15 13:52:35 -0400
commitef6c4964c5b9c63ee3742a8ca1ebe3ab6515c16b (patch)
tree5463d6a198e820759782099feda3f42ac088fc31 /Utility/LogFile.hs
parentb236c46dbb20cfbb42201b7cccdaa153b7bd2ed1 (diff)
webapp: Now has a page to view the log, accessed from the control menu.
Diffstat (limited to 'Utility/LogFile.hs')
-rw-r--r--Utility/LogFile.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Utility/LogFile.hs b/Utility/LogFile.hs
index c45a1d405..1985b7eda 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