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