From c4f1b6f21b121933da8e424eee1a7ff87b535755 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Tue, 1 Apr 2014 10:19:07 -0400 Subject: Forward-port to yesod 1.2.5.2 --- Application.hs | 41 +++++++++++++++++++++++++++++++---------- Foundation.hs | 2 +- sflctimekeeper.cabal | 9 +++++---- tests/main.hs | 1 + 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Application.hs b/Application.hs index b0fb61e..266475b 100644 --- a/Application.hs +++ b/Application.hs @@ -12,12 +12,18 @@ import Yesod.Default.Config import Yesod.Default.Main import Yesod.Default.Handlers import Network.Wai.Middleware.RequestLogger + ( mkRequestLogger, outputFormat, OutputFormat (..), IPAddrSource (..), destination + ) +import qualified Network.Wai.Middleware.RequestLogger as RequestLogger import qualified Database.Persist import Database.Persist.Sql (runMigration) -import Network.HTTP.Conduit (newManager, def) +import Network.HTTP.Conduit (newManager, conduitManagerSettings) import Control.Monad.Logger (runLoggingT) -import System.IO (stdout) -import System.Log.FastLogger (mkLogger) +import Control.Concurrent (forkIO, threadDelay) +import System.Log.FastLogger (newStdoutLoggerSet, defaultBufSize) +import Network.Wai.Logger (clockDateCacher) +import Data.Default (def) +import Yesod.Core.Types (loggerSet, Logger (Logger)) -- Import all relevant handler modules here. -- Don't forget to add new modules to your cabal file! @@ -36,7 +42,7 @@ mkYesodDispatch "App" resourcesApp -- performs initialization and creates a WAI application. This is also the -- place to put your migrate statements to have automatic database -- migrations handled by Yesod. -makeApplication :: AppConfig DefaultEnv Extra -> IO Application +makeApplication :: AppConfig DefaultEnv Extra -> IO (Application, LogFunc) makeApplication conf = do foundation <- makeFoundation conf @@ -46,25 +52,40 @@ makeApplication conf = do if development then Detailed True else Apache FromSocket - , destination = Logger $ appLogger foundation + , destination = RequestLogger.Logger $ loggerSet $ appLogger foundation } -- Create the WAI application and apply middlewares app <- toWaiAppPlain foundation - return $ logWare app + let logFunc = messageLoggerSource foundation (appLogger foundation) + return (logWare app, logFunc) -- | Loads up any necessary settings, creates your foundation datatype, and -- performs some initialization. makeFoundation :: AppConfig DefaultEnv Extra -> IO App makeFoundation conf = do - manager <- newManager def + manager <- newManager conduitManagerSettings s <- staticSite dbconf <- withYamlEnvironment "config/sqlite.yml" (appEnv conf) Database.Persist.loadConfig >>= Database.Persist.applyEnv p <- Database.Persist.createPoolConfig (dbconf :: Settings.PersistConf) - logger <- mkLogger True stdout - let foundation = App conf s p manager dbconf logger + + loggerSet' <- newStdoutLoggerSet defaultBufSize + (getter, updater) <- clockDateCacher + + -- If the Yesod logger (as opposed to the request logger middleware) is + -- used less than once a second on average, you may prefer to omit this + -- thread and use "(updater >> getter)" in place of "getter" below. That + -- would update the cache every time it is used, instead of every second. + let updateLoop = do + threadDelay 1000000 + updater + updateLoop + _ <- forkIO updateLoop + + let logger = Yesod.Core.Types.Logger loggerSet' getter + foundation = App conf s p manager dbconf logger -- Perform database migration using our application's logging settings. runLoggingT @@ -76,7 +97,7 @@ makeFoundation conf = do -- for yesod devel getApplicationDev :: IO (Int, Application) getApplicationDev = - defaultDevelApp loader makeApplication + defaultDevelApp loader (fmap fst . makeApplication) where loader = Yesod.Default.Config.loadConfig (configSettings Development) { csParseExtra = parseExtra diff --git a/Foundation.hs b/Foundation.hs index c58c9ec..2d8f748 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -18,7 +18,7 @@ import Settings (widgetFile, Extra (..)) import Model import Text.Jasmine (minifym) import Text.Hamlet (hamletFile) -import System.Log.FastLogger (Logger) +import Yesod.Core.Types (Logger) -- | The site argument for your application. This can be a good place to -- keep settings and values requiring initialization before your application diff --git a/sflctimekeeper.cabal b/sflctimekeeper.cabal index cc3ee61..d5d78ac 100644 --- a/sflctimekeeper.cabal +++ b/sflctimekeeper.cabal @@ -77,20 +77,21 @@ library , shakespeare-text >= 1.0 && < 1.1 , hjsmin >= 0.1 && < 0.2 , monad-control >= 0.3 && < 0.4 - , wai-extra >= 1.3 && < 1.4 + , wai >= 1.3 + , wai-extra >= 2.0 , yaml >= 0.8 && < 0.9 - , http-conduit >= 1.8 && < 1.10 , directory >= 1.1 && < 1.3 - , warp >= 1.3 && < 1.4 + , warp >= 1.3 , data-default , aeson , conduit >= 1.0 + , http-conduit >= 2.0 , monad-logger >= 0.3 , fast-logger >= 0.3 + , wai-logger >= 2.0 , base64-bytestring , case-insensitive , time - , wai , transformers executable sflctimekeeper diff --git a/tests/main.hs b/tests/main.hs index 672220d..a869b66 100644 --- a/tests/main.hs +++ b/tests/main.hs @@ -7,6 +7,7 @@ module Main where import Import import Yesod.Default.Config import Yesod.Test +import Test.Hspec (hspec) import Application (makeFoundation) import HomeTest -- cgit v1.2.3