Add log-level config
This commit is contained in:
committed by
Steve Chavez
parent
60398ad538
commit
e9efcc70a5
@@ -65,9 +65,9 @@ import PostgREST.Types
|
||||
import Protolude hiding (Proxy, intercalate, toS)
|
||||
import Protolude.Conv (toS)
|
||||
|
||||
postgrest :: LogSetup -> IORef AppConfig -> IORef (Maybe DbStructure) -> P.Pool -> IO UTCTime -> IO () -> Application
|
||||
postgrest logS refConf refDbStructure pool getTime connWorker =
|
||||
pgrstMiddleware logS $ \ req respond -> do
|
||||
postgrest :: LogLevel -> IORef AppConfig -> IORef (Maybe DbStructure) -> P.Pool -> IO UTCTime -> IO () -> Application
|
||||
postgrest logLev refConf refDbStructure pool getTime connWorker =
|
||||
pgrstMiddleware logLev $ \ req respond -> do
|
||||
time <- getTime
|
||||
body <- strictRequestBody req
|
||||
maybeDbStructure <- readIORef refDbStructure
|
||||
|
||||
+17
-2
@@ -58,7 +58,8 @@ import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>))
|
||||
import PostgREST.Auth (parseSecret)
|
||||
import PostgREST.Parsers (pRoleClaimKey)
|
||||
import PostgREST.Private.ProxyUri (isMalformedProxyUri)
|
||||
import PostgREST.Types (JSPath, JSPathExp (..))
|
||||
import PostgREST.Types (JSPath, JSPathExp (..),
|
||||
LogLevel (..))
|
||||
import Protolude hiding (concat, hPutStrLn,
|
||||
intercalate, null, replace, take,
|
||||
toS, (<>))
|
||||
@@ -94,6 +95,8 @@ data AppConfig = AppConfig {
|
||||
, configRawMediaTypes :: [B.ByteString]
|
||||
|
||||
, configJWKS :: Maybe JWKSet
|
||||
|
||||
, configLogLevel :: LogLevel
|
||||
}
|
||||
|
||||
configPoolTimeout' :: (Fractional a) => AppConfig -> a
|
||||
@@ -190,9 +193,11 @@ readPathShowHelp = customExecParser parserPrefs opts
|
||||
|
|
||||
|## content types to produce raw output
|
||||
|# raw-media-types="image/png, image/jpg"
|
||||
|
|
||||
|## logging level. The admitted values are: info and crit
|
||||
|# log-level = "info"
|
||||
|]
|
||||
|
||||
|
||||
-- | Parse the config file
|
||||
readAppConfig :: FilePath -> IO AppConfig
|
||||
readAppConfig cfgPath = do
|
||||
@@ -234,6 +239,7 @@ readAppConfig cfgPath = do
|
||||
<*> optString "root-spec"
|
||||
<*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types")
|
||||
<*> pure Nothing
|
||||
<*> parseLogLevel "log-level"
|
||||
|
||||
parseSocketFileMode :: C.Key -> C.Parser C.Config (Either Text FileMode)
|
||||
parseSocketFileMode k =
|
||||
@@ -257,6 +263,15 @@ readAppConfig cfgPath = do
|
||||
(Just "") -> pure Nothing
|
||||
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 k = C.required k C.string
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import Network.Wai.Middleware.Static (only, staticPolicy)
|
||||
import PostgREST.ApiRequest (ApiRequest (..))
|
||||
import PostgREST.Config (AppConfig (..))
|
||||
import PostgREST.QueryBuilder (setLocalQuery, setLocalSearchPathQuery)
|
||||
import PostgREST.Types (LogSetup (..))
|
||||
import PostgREST.Types (LogLevel (..))
|
||||
import Protolude hiding (head, toS)
|
||||
import Protolude.Conv (toS)
|
||||
|
||||
@@ -57,9 +57,9 @@ runPgLocals conf claims app req = do
|
||||
anon = JSON.String . toS $ configAnonRole conf
|
||||
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
||||
|
||||
pgrstMiddleware :: LogSetup -> Application -> Application
|
||||
pgrstMiddleware logs =
|
||||
(if logs == LogQuiet then id else logStdout)
|
||||
pgrstMiddleware :: LogLevel -> Application -> Application
|
||||
pgrstMiddleware logLev =
|
||||
(if logLev == LogCrit then id else logStdout)
|
||||
. gzip def
|
||||
. cors corsPolicy
|
||||
. staticPolicy (only [("favicon.ico", "static/favicon.ico")])
|
||||
|
||||
@@ -539,5 +539,4 @@ data ConnectionStatus
|
||||
| FatalConnectionError Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | Logging setup
|
||||
data LogSetup = LogQuiet | LogStdout deriving (Eq, Show)
|
||||
data LogLevel = LogCrit | LogInfo deriving (Eq, Show)
|
||||
|
||||
Reference in New Issue
Block a user