Add log-level config
This commit is contained in:
committed by
Steve Chavez
parent
60398ad538
commit
e9efcc70a5
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #1119, Allow config file reloading with SIGUSR2 - @steve-chavez
|
- #1119, Allow config file reloading with SIGUSR2 - @steve-chavez
|
||||||
- #1558, Allow 'Bearer' with and without capitalization as authentication schema - @wolfgangwalther
|
- #1558, Allow 'Bearer' with and without capitalization as authentication schema - @wolfgangwalther
|
||||||
- #1559, No downtime when reloading the schema cache with SIGUSR1 - @steve-chavez
|
- #1559, No downtime when reloading the schema cache with SIGUSR1 - @steve-chavez
|
||||||
|
- #504, Add `log-level` config option - @steve-chavez
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -34,8 +34,7 @@ import PostgREST.DbStructure (getDbStructure, getPgVersion)
|
|||||||
import PostgREST.Error (PgError (PgError), checkIsFatal,
|
import PostgREST.Error (PgError (PgError), checkIsFatal,
|
||||||
errorPayload)
|
errorPayload)
|
||||||
import PostgREST.Types (ConnectionStatus (..), DbStructure,
|
import PostgREST.Types (ConnectionStatus (..), DbStructure,
|
||||||
LogSetup (..), PgVersion (..),
|
PgVersion (..), minimumPgVersion)
|
||||||
minimumPgVersion)
|
|
||||||
import Protolude hiding (hPutStrLn, head, toS)
|
import Protolude hiding (hPutStrLn, head, toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
|
|
||||||
@@ -78,6 +77,7 @@ main = do
|
|||||||
defaultSettings
|
defaultSettings
|
||||||
poolSize = configPoolSize conf
|
poolSize = configPoolSize conf
|
||||||
poolTimeout = configPoolTimeout' conf
|
poolTimeout = configPoolTimeout' conf
|
||||||
|
logLevel = configLogLevel conf
|
||||||
|
|
||||||
-- create connection pool with the provided settings, returns either a 'Connection' or a 'ConnectionError'. Does not throw.
|
-- create connection pool with the provided settings, returns either a 'Connection' or a 'ConnectionError'. Does not throw.
|
||||||
pool <- P.acquire (poolSize, poolTimeout, dbUri)
|
pool <- P.acquire (poolSize, poolTimeout, dbUri)
|
||||||
@@ -133,7 +133,7 @@ main = do
|
|||||||
|
|
||||||
let postgrestApplication =
|
let postgrestApplication =
|
||||||
postgrest
|
postgrest
|
||||||
LogStdout
|
logLevel
|
||||||
refConf
|
refConf
|
||||||
refDbStructure
|
refDbStructure
|
||||||
pool
|
pool
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ import PostgREST.Types
|
|||||||
import Protolude hiding (Proxy, intercalate, toS)
|
import Protolude hiding (Proxy, intercalate, toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
|
|
||||||
postgrest :: LogSetup -> IORef AppConfig -> IORef (Maybe DbStructure) -> P.Pool -> IO UTCTime -> IO () -> Application
|
postgrest :: LogLevel -> IORef AppConfig -> IORef (Maybe DbStructure) -> P.Pool -> IO UTCTime -> IO () -> Application
|
||||||
postgrest logS refConf refDbStructure pool getTime connWorker =
|
postgrest logLev refConf refDbStructure pool getTime connWorker =
|
||||||
pgrstMiddleware logS $ \ req respond -> do
|
pgrstMiddleware logLev $ \ req respond -> do
|
||||||
time <- getTime
|
time <- getTime
|
||||||
body <- strictRequestBody req
|
body <- strictRequestBody req
|
||||||
maybeDbStructure <- readIORef refDbStructure
|
maybeDbStructure <- readIORef refDbStructure
|
||||||
|
|||||||
+17
-2
@@ -58,7 +58,8 @@ import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>))
|
|||||||
import PostgREST.Auth (parseSecret)
|
import PostgREST.Auth (parseSecret)
|
||||||
import PostgREST.Parsers (pRoleClaimKey)
|
import PostgREST.Parsers (pRoleClaimKey)
|
||||||
import PostgREST.Private.ProxyUri (isMalformedProxyUri)
|
import PostgREST.Private.ProxyUri (isMalformedProxyUri)
|
||||||
import PostgREST.Types (JSPath, JSPathExp (..))
|
import PostgREST.Types (JSPath, JSPathExp (..),
|
||||||
|
LogLevel (..))
|
||||||
import Protolude hiding (concat, hPutStrLn,
|
import Protolude hiding (concat, hPutStrLn,
|
||||||
intercalate, null, replace, take,
|
intercalate, null, replace, take,
|
||||||
toS, (<>))
|
toS, (<>))
|
||||||
@@ -94,6 +95,8 @@ data AppConfig = AppConfig {
|
|||||||
, configRawMediaTypes :: [B.ByteString]
|
, configRawMediaTypes :: [B.ByteString]
|
||||||
|
|
||||||
, configJWKS :: Maybe JWKSet
|
, configJWKS :: Maybe JWKSet
|
||||||
|
|
||||||
|
, configLogLevel :: LogLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
configPoolTimeout' :: (Fractional a) => AppConfig -> a
|
configPoolTimeout' :: (Fractional a) => AppConfig -> a
|
||||||
@@ -190,9 +193,11 @@ readPathShowHelp = customExecParser parserPrefs opts
|
|||||||
|
|
|
|
||||||
|## content types to produce raw output
|
|## content types to produce raw output
|
||||||
|# raw-media-types="image/png, image/jpg"
|
|# raw-media-types="image/png, image/jpg"
|
||||||
|
|
|
||||||
|
|## logging level. The admitted values are: info and crit
|
||||||
|
|# log-level = "info"
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
|
||||||
-- | Parse the config file
|
-- | Parse the config file
|
||||||
readAppConfig :: FilePath -> IO AppConfig
|
readAppConfig :: FilePath -> IO AppConfig
|
||||||
readAppConfig cfgPath = do
|
readAppConfig cfgPath = do
|
||||||
@@ -234,6 +239,7 @@ readAppConfig cfgPath = do
|
|||||||
<*> optString "root-spec"
|
<*> optString "root-spec"
|
||||||
<*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types")
|
<*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types")
|
||||||
<*> pure Nothing
|
<*> pure Nothing
|
||||||
|
<*> parseLogLevel "log-level"
|
||||||
|
|
||||||
parseSocketFileMode :: C.Key -> C.Parser C.Config (Either Text FileMode)
|
parseSocketFileMode :: C.Key -> C.Parser C.Config (Either Text FileMode)
|
||||||
parseSocketFileMode k =
|
parseSocketFileMode k =
|
||||||
@@ -257,6 +263,15 @@ readAppConfig cfgPath = do
|
|||||||
(Just "") -> pure Nothing
|
(Just "") -> pure Nothing
|
||||||
aud' -> pure aud'
|
aud' -> pure aud'
|
||||||
|
|
||||||
|
parseLogLevel :: C.Key -> C.Parser C.Config LogLevel
|
||||||
|
parseLogLevel k =
|
||||||
|
C.optional k C.string >>= \case
|
||||||
|
Nothing -> pure LogInfo
|
||||||
|
Just "" -> pure LogInfo
|
||||||
|
Just "crit" -> pure LogCrit
|
||||||
|
Just "info" -> pure LogInfo
|
||||||
|
Just _ -> fail "Invalid logging level. Check your configuration."
|
||||||
|
|
||||||
reqString :: C.Key -> C.Parser C.Config Text
|
reqString :: C.Key -> C.Parser C.Config Text
|
||||||
reqString k = C.required k C.string
|
reqString k = C.required k C.string
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import Network.Wai.Middleware.Static (only, staticPolicy)
|
|||||||
import PostgREST.ApiRequest (ApiRequest (..))
|
import PostgREST.ApiRequest (ApiRequest (..))
|
||||||
import PostgREST.Config (AppConfig (..))
|
import PostgREST.Config (AppConfig (..))
|
||||||
import PostgREST.QueryBuilder (setLocalQuery, setLocalSearchPathQuery)
|
import PostgREST.QueryBuilder (setLocalQuery, setLocalSearchPathQuery)
|
||||||
import PostgREST.Types (LogSetup (..))
|
import PostgREST.Types (LogLevel (..))
|
||||||
import Protolude hiding (head, toS)
|
import Protolude hiding (head, toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
|
|
||||||
@@ -57,9 +57,9 @@ runPgLocals conf claims app req = do
|
|||||||
anon = JSON.String . toS $ configAnonRole conf
|
anon = JSON.String . toS $ configAnonRole conf
|
||||||
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
||||||
|
|
||||||
pgrstMiddleware :: LogSetup -> Application -> Application
|
pgrstMiddleware :: LogLevel -> Application -> Application
|
||||||
pgrstMiddleware logs =
|
pgrstMiddleware logLev =
|
||||||
(if logs == LogQuiet then id else logStdout)
|
(if logLev == LogCrit then id else logStdout)
|
||||||
. gzip def
|
. gzip def
|
||||||
. cors corsPolicy
|
. cors corsPolicy
|
||||||
. staticPolicy (only [("favicon.ico", "static/favicon.ico")])
|
. staticPolicy (only [("favicon.ico", "static/favicon.ico")])
|
||||||
|
|||||||
@@ -539,5 +539,4 @@ data ConnectionStatus
|
|||||||
| FatalConnectionError Text
|
| FatalConnectionError Text
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
-- | Logging setup
|
data LogLevel = LogCrit | LogInfo deriving (Eq, Show)
|
||||||
data LogSetup = LogQuiet | LogStdout deriving (Eq, Show)
|
|
||||||
|
|||||||
+3
-3
@@ -15,7 +15,7 @@ import Test.Hspec
|
|||||||
import PostgREST.App (postgrest)
|
import PostgREST.App (postgrest)
|
||||||
import PostgREST.Config (AppConfig (..))
|
import PostgREST.Config (AppConfig (..))
|
||||||
import PostgREST.DbStructure (getDbStructure, getPgVersion)
|
import PostgREST.DbStructure (getDbStructure, getPgVersion)
|
||||||
import PostgREST.Types (LogSetup (..), pgVersion95, pgVersion96)
|
import PostgREST.Types (LogLevel (..), pgVersion95, pgVersion96)
|
||||||
import Protolude hiding (toList, toS)
|
import Protolude hiding (toList, toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
import SpecHelper
|
import SpecHelper
|
||||||
@@ -67,13 +67,13 @@ main = do
|
|||||||
-- For tests that run with the same refDbStructure
|
-- For tests that run with the same refDbStructure
|
||||||
app cfg = do
|
app cfg = do
|
||||||
refConf <- newIORef $ cfg testDbConn
|
refConf <- newIORef $ cfg testDbConn
|
||||||
return ((), postgrest LogQuiet refConf refDbStructure pool getTime $ pure ())
|
return ((), postgrest LogCrit refConf refDbStructure pool getTime $ pure ())
|
||||||
|
|
||||||
-- For tests that run with a different DbStructure(depends on configSchemas)
|
-- For tests that run with a different DbStructure(depends on configSchemas)
|
||||||
appDbs cfg = do
|
appDbs cfg = do
|
||||||
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) actualPgVersion
|
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) actualPgVersion
|
||||||
refConf <- newIORef $ cfg testDbConn
|
refConf <- newIORef $ cfg testDbConn
|
||||||
return ((), postgrest LogQuiet refConf dbs pool getTime $ pure ())
|
return ((), postgrest LogCrit refConf dbs pool getTime $ pure ())
|
||||||
|
|
||||||
let withApp = app testCfg
|
let withApp = app testCfg
|
||||||
maxRowsApp = app testMaxRowsCfg
|
maxRowsApp = app testMaxRowsCfg
|
||||||
|
|||||||
+2
-1
@@ -24,7 +24,7 @@ import Text.Heredoc
|
|||||||
|
|
||||||
import PostgREST.Auth (parseSecret)
|
import PostgREST.Auth (parseSecret)
|
||||||
import PostgREST.Config (AppConfig (..))
|
import PostgREST.Config (AppConfig (..))
|
||||||
import PostgREST.Types (JSPathExp (..))
|
import PostgREST.Types (JSPathExp (..), LogLevel (..))
|
||||||
import Protolude hiding (toS)
|
import Protolude hiding (toS)
|
||||||
import Protolude.Conv (toS)
|
import Protolude.Conv (toS)
|
||||||
|
|
||||||
@@ -89,6 +89,7 @@ _baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
|
|||||||
, configRootSpec = Nothing
|
, configRootSpec = Nothing
|
||||||
, configRawMediaTypes = []
|
, configRawMediaTypes = []
|
||||||
, configJWKS = parseSecret <$> secret
|
, configJWKS = parseSecret <$> secret
|
||||||
|
, configLogLevel = LogCrit
|
||||||
}
|
}
|
||||||
|
|
||||||
testCfg :: Text -> AppConfig
|
testCfg :: Text -> AppConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user