Updated scaffolding: proper logging for Persistent
This commit is contained in:
parent
27cfef6edb
commit
b83835b421
@ -203,7 +203,7 @@ instance Yesod App where
|
||||
-- The page to be redirected to when authentication is required.
|
||||
authRoute _ = Just $ AuthR LoginR
|
||||
|
||||
-- Routes not requiring authenitcation.
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
||||
@ -34,7 +34,6 @@ module Application
|
||||
) where
|
||||
|
||||
import Import
|
||||
import Settings
|
||||
import Yesod.Auth
|
||||
import Yesod.Default.Config
|
||||
import Yesod.Default.Main
|
||||
@ -45,6 +44,7 @@ import Network.Wai.Middleware.RequestLogger
|
||||
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
||||
import qualified Database.Persist
|
||||
import Database.Persist.Sql (runMigration)
|
||||
import Database.Persist.MySQL (createMySQLPool, myConnInfo, myPoolSize)
|
||||
import Network.HTTP.Client.Conduit (newManager)
|
||||
import Control.Monad.Logger (runLoggingT)
|
||||
import System.Log.FastLogger (newStdoutLoggerSet, defaultBufSize)
|
||||
@ -92,13 +92,12 @@ makeFoundation conf = do
|
||||
dbconf <- withYamlEnvironment "config/mysql.yml" (appEnv conf)
|
||||
Database.Persist.loadConfig >>=
|
||||
Database.Persist.applyEnv
|
||||
p <- Database.Persist.createPoolConfig (dbconf :: Settings.PersistConf)
|
||||
|
||||
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
||||
(getter, _) <- clockDateCacher
|
||||
|
||||
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
||||
foundation = App
|
||||
mkFoundation p = App
|
||||
{ settings = conf
|
||||
, getStatic = s
|
||||
, connPool = p
|
||||
@ -106,11 +105,16 @@ makeFoundation conf = do
|
||||
, persistConfig = dbconf
|
||||
, appLogger = logger
|
||||
}
|
||||
tempFoundation = mkFoundation $ error "connPool forced in tempFoundation"
|
||||
logFunc = messageLoggerSource tempFoundation logger
|
||||
|
||||
p <- flip runLoggingT logFunc
|
||||
$ createMySQLPool (myConnInfo dbconf) (myPoolSize dbconf)
|
||||
let foundation = mkFoundation p
|
||||
|
||||
-- Perform database migration using our application's logging settings.
|
||||
runLoggingT
|
||||
flip runLoggingT logFunc
|
||||
(Database.Persist.runPool dbconf (runMigration migrateAll) p)
|
||||
(messageLoggerSource foundation logger)
|
||||
|
||||
return foundation
|
||||
|
||||
@ -210,7 +214,7 @@ instance Yesod App where
|
||||
-- The page to be redirected to when authentication is required.
|
||||
authRoute _ = Just $ AuthR LoginR
|
||||
|
||||
-- Routes not requiring authenitcation.
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
||||
@ -35,7 +35,6 @@ module Application
|
||||
) where
|
||||
|
||||
import Import
|
||||
import Settings
|
||||
import Yesod.Auth
|
||||
import Yesod.Default.Config
|
||||
import Yesod.Default.Main
|
||||
@ -46,6 +45,7 @@ import Network.Wai.Middleware.RequestLogger
|
||||
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
||||
import qualified Database.Persist
|
||||
import Database.Persist.Sql (runMigration)
|
||||
import Database.Persist.Postgresql (createPostgresqlPool, pgConnStr, pgPoolSize)
|
||||
import Network.HTTP.Client.Conduit (newManager)
|
||||
import Yesod.Fay (getFaySite)
|
||||
import Control.Monad.Logger (runLoggingT)
|
||||
@ -95,13 +95,12 @@ makeFoundation conf = do
|
||||
dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv conf)
|
||||
Database.Persist.loadConfig >>=
|
||||
Database.Persist.applyEnv
|
||||
p <- Database.Persist.createPoolConfig (dbconf :: Settings.PersistConf)
|
||||
|
||||
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
||||
(getter, _) <- clockDateCacher
|
||||
|
||||
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
||||
foundation = App
|
||||
mkFoundation p = App
|
||||
{ settings = conf
|
||||
, getStatic = s
|
||||
, connPool = p
|
||||
@ -110,11 +109,16 @@ makeFoundation conf = do
|
||||
, fayCommandHandler = onCommand
|
||||
, appLogger = logger
|
||||
}
|
||||
tempFoundation = mkFoundation $ error "connPool forced in tempFoundation"
|
||||
logFunc = messageLoggerSource tempFoundation logger
|
||||
|
||||
p <- flip runLoggingT logFunc
|
||||
$ createPostgresqlPool (pgConnStr dbconf) (pgPoolSize dbconf)
|
||||
let foundation = mkFoundation p
|
||||
|
||||
-- Perform database migration using our application's logging settings.
|
||||
runLoggingT
|
||||
flip runLoggingT logFunc
|
||||
(Database.Persist.runPool dbconf (runMigration migrateAll) p)
|
||||
(messageLoggerSource foundation logger)
|
||||
|
||||
return foundation
|
||||
|
||||
@ -215,7 +219,7 @@ instance Yesod App where
|
||||
-- The page to be redirected to when authentication is required.
|
||||
authRoute _ = Just $ AuthR LoginR
|
||||
|
||||
-- Routes not requiring authenitcation.
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
||||
@ -34,7 +34,6 @@ module Application
|
||||
) where
|
||||
|
||||
import Import
|
||||
import Settings
|
||||
import Yesod.Auth
|
||||
import Yesod.Default.Config
|
||||
import Yesod.Default.Main
|
||||
@ -45,6 +44,7 @@ import Network.Wai.Middleware.RequestLogger
|
||||
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
||||
import qualified Database.Persist
|
||||
import Database.Persist.Sql (runMigration)
|
||||
import Database.Persist.Postgresql (createPostgresqlPool, pgConnStr, pgPoolSize)
|
||||
import Network.HTTP.Client.Conduit (newManager)
|
||||
import Control.Monad.Logger (runLoggingT)
|
||||
import System.Log.FastLogger (newStdoutLoggerSet, defaultBufSize)
|
||||
@ -92,13 +92,12 @@ makeFoundation conf = do
|
||||
dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv conf)
|
||||
Database.Persist.loadConfig >>=
|
||||
Database.Persist.applyEnv
|
||||
p <- Database.Persist.createPoolConfig (dbconf :: Settings.PersistConf)
|
||||
|
||||
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
||||
(getter, _) <- clockDateCacher
|
||||
|
||||
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
||||
foundation = App
|
||||
mkFoundation p = App
|
||||
{ settings = conf
|
||||
, getStatic = s
|
||||
, connPool = p
|
||||
@ -106,11 +105,16 @@ makeFoundation conf = do
|
||||
, persistConfig = dbconf
|
||||
, appLogger = logger
|
||||
}
|
||||
tempFoundation = mkFoundation $ error "connPool forced in tempFoundation"
|
||||
logFunc = messageLoggerSource tempFoundation logger
|
||||
|
||||
p <- flip runLoggingT logFunc
|
||||
$ createPostgresqlPool (pgConnStr dbconf) (pgPoolSize dbconf)
|
||||
let foundation = mkFoundation p
|
||||
|
||||
-- Perform database migration using our application's logging settings.
|
||||
runLoggingT
|
||||
flip runLoggingT logFunc
|
||||
(Database.Persist.runPool dbconf (runMigration migrateAll) p)
|
||||
(messageLoggerSource foundation logger)
|
||||
|
||||
return foundation
|
||||
|
||||
@ -210,7 +214,7 @@ instance Yesod App where
|
||||
-- The page to be redirected to when authentication is required.
|
||||
authRoute _ = Just $ AuthR LoginR
|
||||
|
||||
-- Routes not requiring authenitcation.
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
||||
@ -34,7 +34,6 @@ module Application
|
||||
) where
|
||||
|
||||
import Import
|
||||
import Settings
|
||||
import Yesod.Auth
|
||||
import Yesod.Default.Config
|
||||
import Yesod.Default.Main
|
||||
@ -45,6 +44,7 @@ import Network.Wai.Middleware.RequestLogger
|
||||
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
||||
import qualified Database.Persist
|
||||
import Database.Persist.Sql (runMigration)
|
||||
import Database.Persist.Sqlite (createSqlitePool, sqlDatabase, sqlPoolSize)
|
||||
import Network.HTTP.Client.Conduit (newManager)
|
||||
import Control.Monad.Logger (runLoggingT)
|
||||
import System.Log.FastLogger (newStdoutLoggerSet, defaultBufSize)
|
||||
@ -92,13 +92,12 @@ makeFoundation conf = do
|
||||
dbconf <- withYamlEnvironment "config/sqlite.yml" (appEnv conf)
|
||||
Database.Persist.loadConfig >>=
|
||||
Database.Persist.applyEnv
|
||||
p <- Database.Persist.createPoolConfig (dbconf :: Settings.PersistConf)
|
||||
|
||||
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
||||
(getter, _) <- clockDateCacher
|
||||
|
||||
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
||||
foundation = App
|
||||
mkFoundation p = App
|
||||
{ settings = conf
|
||||
, getStatic = s
|
||||
, connPool = p
|
||||
@ -106,11 +105,16 @@ makeFoundation conf = do
|
||||
, persistConfig = dbconf
|
||||
, appLogger = logger
|
||||
}
|
||||
tempFoundation = mkFoundation $ error "connPool forced in tempFoundation"
|
||||
logFunc = messageLoggerSource tempFoundation logger
|
||||
|
||||
p <- flip runLoggingT logFunc
|
||||
$ createSqlitePool (sqlDatabase dbconf) (sqlPoolSize dbconf)
|
||||
let foundation = mkFoundation p
|
||||
|
||||
-- Perform database migration using our application's logging settings.
|
||||
runLoggingT
|
||||
flip runLoggingT logFunc
|
||||
(Database.Persist.runPool dbconf (runMigration migrateAll) p)
|
||||
(messageLoggerSource foundation logger)
|
||||
|
||||
return foundation
|
||||
|
||||
@ -210,7 +214,7 @@ instance Yesod App where
|
||||
-- The page to be redirected to when authentication is required.
|
||||
authRoute _ = Just $ AuthR LoginR
|
||||
|
||||
-- Routes not requiring authenitcation.
|
||||
-- Routes not requiring authentication.
|
||||
isAuthorized (AuthR _) _ = return Authorized
|
||||
isAuthorized FaviconR _ = return Authorized
|
||||
isAuthorized RobotsR _ = return Authorized
|
||||
|
||||
Loading…
Reference in New Issue
Block a user