summaryrefslogtreecommitdiff
path: root/src/Propellor/Message.hs
diff options
context:
space:
mode:
authorJoey Hess2014-11-25 18:55:07 -0400
committerJoey Hess2014-11-25 18:55:12 -0400
commite07dc9b1d336e86ce51b2a94fcfa943cc1650afd (patch)
treed2a508a12c41be061c51621c085b79e39efb4cb1 /src/Propellor/Message.hs
parent7d0f79a0c7656a0dd68235c93e2f770b0b1b6ea3 (diff)
propellor.debug can be set in the git config to enable more persistent debugging output.
Diffstat (limited to 'src/Propellor/Message.hs')
-rw-r--r--src/Propellor/Message.hs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/Propellor/Message.hs b/src/Propellor/Message.hs
index 09a92538..49dc4934 100644
--- a/src/Propellor/Message.hs
+++ b/src/Propellor/Message.hs
@@ -11,10 +11,13 @@ import System.Log.Handler.Simple
import "mtl" Control.Monad.Reader
import Data.Maybe
import Control.Applicative
+import System.Directory
+import Control.Monad.IfElse
import Propellor.Types
import Utility.Monad
import Utility.Env
+import Utility.Process
data MessageHandle
= ConsoleMessageHandle
@@ -99,17 +102,23 @@ colorLine h intensity color msg = do
putStrLn ""
hFlush stdout
--- | Causes a debug message to be displayed when PROPELLOR_DEBUG=1
debug :: [String] -> IO ()
debug = debugM "propellor" . unwords
checkDebugMode :: IO ()
checkDebugMode = go =<< getEnv "PROPELLOR_DEBUG"
where
- go (Just "1") = do
- f <- setFormatter
- <$> streamHandler stderr DEBUG
- <*> pure (simpleLogFormatter "[$time] $msg")
- updateGlobalLogger rootLoggerName $
- setLevel DEBUG . setHandlers [f]
- go _ = noop
+ go (Just "1") = enableDebugMode
+ go (Just _) = noop
+ go Nothing = whenM (doesDirectoryExist ".git") $
+ whenM (any (== "1") . lines <$> getgitconfig) $
+ enableDebugMode
+ getgitconfig = readProcess "git" ["config", "propellor.debug"]
+
+enableDebugMode :: IO ()
+enableDebugMode = do
+ f <- setFormatter
+ <$> streamHandler stderr DEBUG
+ <*> pure (simpleLogFormatter "[$time] $msg")
+ updateGlobalLogger rootLoggerName $
+ setLevel DEBUG . setHandlers [f]