summaryrefslogtreecommitdiff
path: root/Utility/LogFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-11 00:39:09 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-11 00:39:09 -0400
commitd5884388b09347835df599d8a0dcea77e6795c10 (patch)
tree2f98ad9d0013b97daa04278bc837ef64967db73a /Utility/LogFile.hs
parentca9ee21bd771e7f94ecd3916f55b10fb3cc8dcbe (diff)
daemonize git annex watch
Diffstat (limited to 'Utility/LogFile.hs')
-rw-r--r--Utility/LogFile.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Utility/LogFile.hs b/Utility/LogFile.hs
new file mode 100644
index 000000000..7ffb63f52
--- /dev/null
+++ b/Utility/LogFile.hs
@@ -0,0 +1,31 @@
+{- log files
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Utility.LogFile where
+
+import Common
+
+import System.Posix
+
+openLog :: FilePath -> IO Fd
+openLog logfile = do
+ rotateLog logfile 0
+ openFd logfile WriteOnly (Just stdFileMode)
+ defaultFileFlags { append = True }
+
+rotateLog :: FilePath -> Int -> IO ()
+rotateLog logfile num
+ | num >= 10 = return ()
+ | otherwise = whenM (doesFileExist currfile) $ do
+ rotateLog logfile (num + 1)
+ renameFile currfile nextfile
+ where
+ currfile = filename num
+ nextfile = filename (num + 1)
+ filename n
+ | n == 0 = logfile
+ | otherwise = logfile ++ "." ++ show n