summaryrefslogtreecommitdiff
path: root/Application.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Application.hs')
-rw-r--r--Application.hs52
1 files changed, 36 insertions, 16 deletions
diff --git a/Application.hs b/Application.hs
index e7d9049..dfd717d 100644
--- a/Application.hs
+++ b/Application.hs
@@ -11,46 +11,66 @@ import Yesod.Auth
import Yesod.Default.Config
import Yesod.Default.Main
import Yesod.Default.Handlers
-import Yesod.Logger (Logger, logBS, toProduction)
-import Network.Wai.Middleware.RequestLogger (logCallback, logCallbackDev)
+import Network.Wai.Middleware.RequestLogger
import qualified Database.Persist.Store
import Database.Persist.GenericSql (runMigration)
import Network.HTTP.Conduit (newManager, def)
+import Control.Monad.Logger (runLoggingT)
+import System.IO (stdout)
+import System.Log.FastLogger (mkLogger)
-- Import all relevant handler modules here.
-- Don't forget to add new modules to your cabal file!
import Handler.Home
+import Handler.Category
+import Handler.Employment
import Handler.User
--- This line actually creates our YesodSite instance. It is the second half
--- of the call to mkYesodData which occurs in Foundation.hs. Please see
--- the comments there for more details.
+-- This line actually creates our YesodDispatch instance. It is the second half
+-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
+-- comments there for more details.
mkYesodDispatch "App" resourcesApp
-- This function allocates resources (such as a database connection pool),
-- 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 -> Logger -> IO Application
-makeApplication conf logger = do
- foundation <- makeFoundation conf setLogger
+makeApplication :: AppConfig DefaultEnv Extra -> IO Application
+makeApplication conf = do
+ foundation <- makeFoundation conf
+
+ -- Initialize the logging middleware
+ logWare <- mkRequestLogger def
+ { outputFormat =
+ if development
+ then Detailed True
+ else Apache FromSocket
+ , destination = Logger $ appLogger foundation
+ }
+
+ -- Create the WAI application and apply middlewares
app <- toWaiAppPlain foundation
return $ logWare app
- where
- setLogger = if development then logger else toProduction logger
- logWare = if development then logCallbackDev (logBS setLogger)
- else logCallback (logBS setLogger)
-makeFoundation :: AppConfig DefaultEnv Extra -> Logger -> IO App
-makeFoundation conf setLogger = do
+-- | 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
s <- staticSite
dbconf <- withYamlEnvironment "config/sqlite.yml" (appEnv conf)
Database.Persist.Store.loadConfig >>=
Database.Persist.Store.applyEnv
p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)
- Database.Persist.Store.runPool dbconf (runMigration migrateAll) p
- return $ App conf setLogger s p manager dbconf
+ logger <- mkLogger True stdout
+ let foundation = App conf s p manager dbconf logger
+
+ -- Perform database migration using our application's logging settings.
+ runLoggingT
+ (Database.Persist.Store.runPool dbconf (runMigration migrateAll) p)
+ (messageLoggerSource foundation logger)
+
+ return foundation
-- for yesod devel
getApplicationDev :: IO (Int, Application)