on master help sign in
Ensure "Listening on 0.0.0.0:8000" message is not garbled
commit9307ec526308f55340b95e199d6aad0850d17d04 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 10 Jan 2015, 22:15 (12 years ago) parent23ab06d
6 files changed+62−52
src/Hakyll/Check.hs+6−7 src/Hakyll/Commands.hs+27−26 src/Hakyll/Core/Runtime.hs+3−4 src/Hakyll/Main.hs+8−7 src/Hakyll/Preview/Server.hs+14−6 tests/Hakyll/Core/Runtime/Tests.hs+4−2
src/Hakyll/Check.hs+6−7
@@ -42,7 +42,7 @@ import qualified Paths_hakyll as Paths_hakyll
4242
4343--------------------------------------------------------------------------------
4444import Hakyll.Core.Configuration
45−import Hakyll.Core.Logger (Logger, Verbosity)
45+import Hakyll.Core.Logger (Logger)
4646import qualified Hakyll.Core.Logger as Logger
4747import Hakyll.Core.Util.File
4848import Hakyll.Web.Html
@@ -54,9 +54,9 @@ data Check = All | InternalLinks
5454
5555
5656--------------------------------------------------------------------------------
57−check :: Configuration -> Verbosity -> Check -> IO ExitCode
58−check config verbosity check' = do
59− ((), write) <- runChecker checkDestination config verbosity check'
57+check :: Configuration -> Logger -> Check -> IO ExitCode
58+check config logger check' = do
59+ ((), write) <- runChecker checkDestination config logger check'
6060 return $ if checkerFaulty write > 0 then ExitFailure 1 else ExitSuccess
6161
6262
@@ -91,10 +91,9 @@ type Checker a = RWST CheckerRead CheckerWrite CheckerState IO a
9191
9292
9393--------------------------------------------------------------------------------
94−runChecker :: Checker a -> Configuration -> Verbosity -> Check
94+runChecker :: Checker a -> Configuration -> Logger -> Check
9595 -> IO (a, CheckerWrite)
96−runChecker checker config verbosity check' = do
97− logger <- Logger.new verbosity
96+runChecker checker config logger check' = do
9897 let read' = CheckerRead
9998 { checkerConfig = config
10099 , checkerLogger = logger
src/Hakyll/Commands.hs+27−26
@@ -14,16 +14,17 @@ module Hakyll.Commands
1414
1515
1616--------------------------------------------------------------------------------
17−import System.Exit (exitWith, ExitCode)
18−import System.IO.Error (catchIOError)
1917import Control.Applicative
20−import Control.Monad (void)
2118import Control.Concurrent
19+import Control.Monad (void)
20+import System.Exit (ExitCode, exitWith)
21+import System.IO.Error (catchIOError)
2222
2323--------------------------------------------------------------------------------
2424import qualified Hakyll.Check as Check
2525import Hakyll.Core.Configuration
26−import Hakyll.Core.Logger (Verbosity)
26+import Hakyll.Core.Logger (Logger)
27+import qualified Hakyll.Core.Logger as Logger
2728import Hakyll.Core.Rules
2829import Hakyll.Core.Rules.Internal
2930import Hakyll.Core.Runtime
@@ -31,7 +32,7 @@ import Hakyll.Core.Util.File
3132
3233--------------------------------------------------------------------------------
3334#ifdef WATCH_SERVER
34−import Hakyll.Preview.Poll (watchUpdates)
35+import Hakyll.Preview.Poll (watchUpdates)
3536#endif
3637
3738#ifdef PREVIEW_SERVER
@@ -41,35 +42,36 @@ import Hakyll.Preview.Server
4142
4243--------------------------------------------------------------------------------
4344-- | Build the site
44−build :: Configuration -> Verbosity -> Rules a -> IO ExitCode
45−build conf verbosity rules = fst <$> run conf verbosity rules
45+build :: Configuration -> Logger -> Rules a -> IO ExitCode
46+build conf logger rules = fst <$> run conf logger rules
47+
4648
4749--------------------------------------------------------------------------------
4850-- | Run the checker and exit
49−check :: Configuration -> Verbosity -> Check.Check -> IO ()
50−check config verbosity check' = Check.check config verbosity check' >>= exitWith
51+check :: Configuration -> Logger -> Check.Check -> IO ()
52+check config logger check' = Check.check config logger check' >>= exitWith
5153
5254
5355--------------------------------------------------------------------------------
5456-- | Remove the output directories
55−clean :: Configuration -> IO ()
56−clean conf = do
57+clean :: Configuration -> Logger -> IO ()
58+clean conf logger = do
5759 remove $ destinationDirectory conf
5860 remove $ storeDirectory conf
5961 remove $ tmpDirectory conf
6062 where
6163 remove dir = do
62− putStrLn $ "Removing " ++ dir ++ "..."
64+ Logger.header logger $ "Removing " ++ dir ++ "..."
6365 removeDirectory dir
6466
6567
6668--------------------------------------------------------------------------------
6769-- | Preview the site
68−preview :: Configuration -> Verbosity -> Rules a -> Int -> IO ()
70+preview :: Configuration -> Logger -> Rules a -> Int -> IO ()
6971#ifdef PREVIEW_SERVER
70−preview conf verbosity rules port = do
72+preview conf logger rules port = do
7173 deprecatedMessage
72− watch conf verbosity "0.0.0.0" port True rules
74+ watch conf logger "0.0.0.0" port True rules
7375 where
7476 deprecatedMessage = mapM_ putStrLn [ "The preview command has been deprecated."
7577 , "Use the watch command for recompilation and serving."
@@ -82,9 +84,9 @@ preview _ _ _ _ = previewServerDisabled
8284--------------------------------------------------------------------------------
8385-- | Watch and recompile for changes
8486
85−watch :: Configuration -> Verbosity -> String -> Int -> Bool -> Rules a -> IO ()
87+watch :: Configuration -> Logger -> String -> Int -> Bool -> Rules a -> IO ()
8688#ifdef WATCH_SERVER
87−watch conf verbosity host port runServer rules = do
89+watch conf logger host port runServer rules = do
8890#ifndef mingw32_HOST_OS
8991 _ <- forkIO $ watchUpdates conf update
9092#else
@@ -97,27 +99,27 @@ watch conf verbosity host port runServer rules = do
9799 server'
98100 where
99101 update = do
100− (_, ruleSet) <- run conf verbosity rules
102+ (_, ruleSet) <- run conf logger rules
101103 return $ rulesPattern ruleSet
102104 loop = threadDelay 100000 >> loop
103− server' = if runServer then server conf host port else loop
105+ server' = if runServer then server conf logger host port else loop
104106#else
105107watch _ _ _ _ _ _ = watchServerDisabled
106108#endif
107109
108110--------------------------------------------------------------------------------
109111-- | Rebuild the site
110−rebuild :: Configuration -> Verbosity -> Rules a -> IO ExitCode
111−rebuild conf verbosity rules =
112− clean conf >> build conf verbosity rules
112+rebuild :: Configuration -> Logger -> Rules a -> IO ExitCode
113+rebuild conf logger rules =
114+ clean conf logger >> build conf logger rules
113115
114116--------------------------------------------------------------------------------
115117-- | Start a server
116−server :: Configuration -> String -> Int -> IO ()
118+server :: Configuration -> Logger -> String -> Int -> IO ()
117119#ifdef PREVIEW_SERVER
118−server conf host port = do
120+server conf logger host port = do
119121 let destination = destinationDirectory conf
120− staticServer destination preServeHook host port
122+ staticServer logger destination preServeHook host port
121123 where
122124 preServeHook _ = return ()
123125#else
@@ -156,4 +158,3 @@ watchServerDisabled =
156158 , "Alternatively, use an external tool to serve your site directory."
157159 ]
158160#endif
159−
src/Hakyll/Core/Runtime.hs+3−4
@@ -30,7 +30,7 @@ import Hakyll.Core.Dependencies
3030import Hakyll.Core.Identifier
3131import Hakyll.Core.Item
3232import Hakyll.Core.Item.SomeItem
33−import Hakyll.Core.Logger (Logger, Verbosity)
33+import Hakyll.Core.Logger (Logger)
3434import qualified Hakyll.Core.Logger as Logger
3535import Hakyll.Core.Provider
3636import Hakyll.Core.Routes
@@ -42,10 +42,9 @@ import Hakyll.Core.Writable
4242
4343
4444--------------------------------------------------------------------------------
45−run :: Configuration -> Verbosity -> Rules a -> IO (ExitCode, RuleSet)
46−run config verbosity rules = do
45+run :: Configuration -> Logger -> Rules a -> IO (ExitCode, RuleSet)
46+run config logger rules = do
4747 -- Initialization
48− logger <- Logger.new verbosity
4948 Logger.header logger "Initialising..."
5049 Logger.message logger "Creating store..."
5150 store <- Store.new (inMemoryCache config) $ storeDirectory config
src/Hakyll/Main.hs+8−7
@@ -40,16 +40,17 @@ hakyllWith conf rules = do
4040 check' =
4141 if internal_links args' then Check.InternalLinks else Check.All
4242
43+ logger <- Logger.new verbosity'
4344 case args' of
44− Build _ -> Commands.build conf verbosity' rules >>= exitWith
45− Check _ _ -> Commands.check conf verbosity' check'
46− Clean _ -> Commands.clean conf
45+ Build _ -> Commands.build conf logger rules >>= exitWith
46+ Check _ _ -> Commands.check conf logger check'
47+ Clean _ -> Commands.clean conf logger
4748 Deploy _ -> Commands.deploy conf >>= exitWith
4849 Help _ -> showHelp
49− Preview _ p -> Commands.preview conf verbosity' rules p
50− Rebuild _ -> Commands.rebuild conf verbosity' rules >>= exitWith
51− Server _ _ _ -> Commands.server conf (host args') (port args')
52− Watch _ _ p s -> Commands.watch conf verbosity' (host args') p (not s) rules
50+ Preview _ p -> Commands.preview conf logger rules p
51+ Rebuild _ -> Commands.rebuild conf logger rules >>= exitWith
52+ Server _ _ _ -> Commands.server conf logger (host args') (port args')
53+ Watch _ _ p s -> Commands.watch conf logger (host args') p (not s) rules
5354
5455
5556--------------------------------------------------------------------------------
src/Hakyll/Preview/Server.hs+14−6
@@ -7,11 +7,16 @@ module Hakyll.Preview.Server
77
88
99--------------------------------------------------------------------------------
10−import Control.Monad.Trans (liftIO)
10+import Control.Monad.Trans (liftIO)
1111import qualified Data.ByteString.Char8 as B
12−import qualified Snap.Core as Snap
13−import qualified Snap.Http.Server as Snap
14−import qualified Snap.Util.FileServe as Snap
12+import qualified Snap.Core as Snap
13+import qualified Snap.Http.Server as Snap
14+import qualified Snap.Util.FileServe as Snap
15+
16+
17+--------------------------------------------------------------------------------
18+import Hakyll.Core.Logger (Logger)
19+import qualified Hakyll.Core.Logger as Logger
1520
1621
1722--------------------------------------------------------------------------------
@@ -30,12 +35,14 @@ static directory preServe =
3035
3136--------------------------------------------------------------------------------
3237-- | Main method, runs a static server in the given directory
33−staticServer :: FilePath -- ^ Directory to serve
38+staticServer :: Logger -- ^ Logger
39+ -> FilePath -- ^ Directory to serve
3440 -> (FilePath -> IO ()) -- ^ Pre-serve hook
3541 -> String -- ^ Host to bind on
3642 -> Int -- ^ Port to listen on
3743 -> IO () -- ^ Blocks forever
38−staticServer directory preServe host port =
44+staticServer logger directory preServe host port = do
45+ Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port
3946 Snap.httpServe config $ static directory preServe
4047 where
4148 -- Snap server config
@@ -43,4 +50,5 @@ staticServer directory preServe host port =
4350 $ Snap.setPort port
4451 $ Snap.setAccessLog Snap.ConfigNoLog
4552 $ Snap.setErrorLog Snap.ConfigNoLog
53+ $ Snap.setVerbose False
4654 $ Snap.emptyConfig
tests/Hakyll/Core/Runtime/Tests.hs+4−2
@@ -28,7 +28,8 @@ tests = testGroup "Hakyll.Core.Runtime.Tests" $
2828--------------------------------------------------------------------------------
2929case01 :: Assertion
3030case01 = do
31− _ <- run testConfiguration Logger.Error $ do
31+ logger <- Logger.new Logger.Error
32+ _ <- run testConfiguration logger $ do
3233 match "images/*" $ do
3334 route idRoute
3435 compile copyFileCompiler
@@ -65,7 +66,8 @@ case01 = do
6566--------------------------------------------------------------------------------
6667case02 :: Assertion
6768case02 = do
68− _ <- run testConfiguration Logger.Error $ do
69+ logger <- Logger.new Logger.Error
70+ _ <- run testConfiguration logger $ do
6971 match "images/favicon.ico" $ do
7072 route $ gsubRoute "images/" (const "")
7173 compile $ makeItem ("Test" :: String)