change: change log-query string value to bool
BREAKING CHANGE As discussed on https://github.com/PostgREST/postgrest/issues/3934#issuecomment-3362806777, this changes log-query to use a bool value, this: - Simplifies config for users. - Reduces effort in testing the different combinations. Closes #3934
This commit is contained in:
committed by
Steve Chavez
parent
e4458abd33
commit
09b088d8ff
@@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
- Drop support for PostgreSQL EOL version 12 by @wolfgangwalther in #3865
|
- Drop support for PostgreSQL EOL version 12 by @wolfgangwalther in #3865
|
||||||
- Replaced `jwt-cache-max-lifetime` config with `jwt-cache-max-entries` by @mkleczek in #4084
|
- Replaced `jwt-cache-max-lifetime` config with `jwt-cache-max-entries` by @mkleczek in #4084
|
||||||
|
- `log-query` config now takes a boolean instead of a string value by @steve-chavez in #3934
|
||||||
|
|
||||||
## [13.0.7] - 2025-09-14
|
## [13.0.7] - 2025-09-14
|
||||||
|
|
||||||
|
|||||||
@@ -714,23 +714,14 @@ log-query
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
=============== =================================
|
=============== =================================
|
||||||
**Type** String
|
**Type** Boolean
|
||||||
**Default** "disabled"
|
**Default** False
|
||||||
**Reloadable** Y
|
**Reloadable** Y
|
||||||
**Environment** PGRST_LOG_QUERY
|
**Environment** PGRST_LOG_QUERY
|
||||||
**In-Database** `n/a`
|
**In-Database** `n/a`
|
||||||
=============== =================================
|
=============== =================================
|
||||||
|
|
||||||
Logs the SQL query for the corresponding request at the current :ref:`log-level`.
|
Logs the SQL query for the corresponding request at the current :ref:`log-level`. See :ref:`sql_query_logs`.
|
||||||
See :ref:`sql_query_logs`.
|
|
||||||
|
|
||||||
.. code:: bash
|
|
||||||
|
|
||||||
# Logs the main SQL query
|
|
||||||
log-query = "main-query"
|
|
||||||
|
|
||||||
# Disables logging the SQL query
|
|
||||||
log-query = "disabled"
|
|
||||||
|
|
||||||
.. _openapi-mode:
|
.. _openapi-mode:
|
||||||
|
|
||||||
|
|||||||
@@ -52,14 +52,12 @@ For diagnostic information about the server itself, PostgREST logs to ``stderr``
|
|||||||
SQL Query Logs
|
SQL Query Logs
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
To log the :ref:`main SQL query <main_query>` executed for a request, set the :ref:`log-query` to ``main-query``.
|
To log the SQL queries executed for a request, set the :ref:`log-query` to ``true``. It will be logged based on the current :ref:`log-level` setting.
|
||||||
It will be logged based on the current :ref:`log-level` setting.
|
|
||||||
For example, with this configuration:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
log-level = "warn"
|
log-level = "warn"
|
||||||
log-query = "main-query"
|
log-query = "true"
|
||||||
|
|
||||||
The SQL queries will only be logged on ``400`` HTTP errors and up.
|
The SQL queries will only be logged on ``400`` HTTP errors and up.
|
||||||
So, if the user requests a resource without sufficient privileges:
|
So, if the user requests a resource without sufficient privileges:
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ import qualified PostgREST.Unix as Unix (installSignalHandlers)
|
|||||||
import PostgREST.ApiRequest (ApiRequest (..))
|
import PostgREST.ApiRequest (ApiRequest (..))
|
||||||
import PostgREST.AppState (AppState)
|
import PostgREST.AppState (AppState)
|
||||||
import PostgREST.Auth.Types (AuthResult (..))
|
import PostgREST.Auth.Types (AuthResult (..))
|
||||||
import PostgREST.Config (AppConfig (..), LogLevel (..),
|
import PostgREST.Config (AppConfig (..), LogLevel (..))
|
||||||
LogQuery (..))
|
|
||||||
import PostgREST.Error (Error)
|
import PostgREST.Error (Error)
|
||||||
import PostgREST.Network (resolveSocketToAddress)
|
import PostgREST.Network (resolveSocketToAddress)
|
||||||
import PostgREST.Observation (Observation (..))
|
import PostgREST.Observation (Observation (..))
|
||||||
@@ -146,7 +145,7 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache authResult@AuthRe
|
|||||||
let mainQ = Query.mainQuery plan conf apiReq authResult configDbPreRequest
|
let mainQ = Query.mainQuery plan conf apiReq authResult configDbPreRequest
|
||||||
tx = MainTx.mainTx mainQ conf authResult apiReq plan sCache
|
tx = MainTx.mainTx mainQ conf authResult apiReq plan sCache
|
||||||
observer = AppState.getObserver appState
|
observer = AppState.getObserver appState
|
||||||
obsQuery s = when (configLogQuery /= LogQueryDisabled) $ observer $ QueryObs mainQ s
|
obsQuery s = when configLogQuery $ observer $ QueryObs mainQ s
|
||||||
|
|
||||||
(txTime, txResult) <- withTiming $ do
|
(txTime, txResult) <- withTiming $ do
|
||||||
case tx of
|
case tx of
|
||||||
|
|||||||
+3
-20
@@ -17,7 +17,6 @@ module PostgREST.Config
|
|||||||
, JSPathExp(..)
|
, JSPathExp(..)
|
||||||
, FilterExp(..)
|
, FilterExp(..)
|
||||||
, LogLevel(..)
|
, LogLevel(..)
|
||||||
, LogQuery(..)
|
|
||||||
, OpenAPIMode(..)
|
, OpenAPIMode(..)
|
||||||
, Proxy(..)
|
, Proxy(..)
|
||||||
, toText
|
, toText
|
||||||
@@ -99,7 +98,7 @@ data AppConfig = AppConfig
|
|||||||
, configJwtSecretIsBase64 :: Bool
|
, configJwtSecretIsBase64 :: Bool
|
||||||
, configJwtCacheMaxEntries :: Int
|
, configJwtCacheMaxEntries :: Int
|
||||||
, configLogLevel :: LogLevel
|
, configLogLevel :: LogLevel
|
||||||
, configLogQuery :: LogQuery
|
, configLogQuery :: Bool
|
||||||
, configOpenApiMode :: OpenAPIMode
|
, configOpenApiMode :: OpenAPIMode
|
||||||
, configOpenApiSecurityActive :: Bool
|
, configOpenApiSecurityActive :: Bool
|
||||||
, configOpenApiServerProxyUri :: Maybe Text
|
, configOpenApiServerProxyUri :: Maybe Text
|
||||||
@@ -128,14 +127,6 @@ dumpLogLevel = \case
|
|||||||
LogInfo -> "info"
|
LogInfo -> "info"
|
||||||
LogDebug -> "debug"
|
LogDebug -> "debug"
|
||||||
|
|
||||||
data LogQuery = LogQueryMain | LogQueryDisabled
|
|
||||||
deriving (Eq)
|
|
||||||
|
|
||||||
dumpLogQuery :: LogQuery -> Text
|
|
||||||
dumpLogQuery = \case
|
|
||||||
LogQueryMain -> "main-query"
|
|
||||||
LogQueryDisabled -> "disabled"
|
|
||||||
|
|
||||||
data OpenAPIMode = OAFollowPriv | OAIgnorePriv | OADisabled
|
data OpenAPIMode = OAFollowPriv | OAIgnorePriv | OADisabled
|
||||||
deriving Eq
|
deriving Eq
|
||||||
|
|
||||||
@@ -179,7 +170,7 @@ toText conf =
|
|||||||
,("jwt-secret-is-base64", T.toLower . show . configJwtSecretIsBase64)
|
,("jwt-secret-is-base64", T.toLower . show . configJwtSecretIsBase64)
|
||||||
,("jwt-cache-max-entries", show . configJwtCacheMaxEntries)
|
,("jwt-cache-max-entries", show . configJwtCacheMaxEntries)
|
||||||
,("log-level", q . dumpLogLevel . configLogLevel)
|
,("log-level", q . dumpLogLevel . configLogLevel)
|
||||||
,("log-query", q . dumpLogQuery . configLogQuery)
|
,("log-query", T.toLower . show . configLogQuery)
|
||||||
,("openapi-mode", q . dumpOpenApiMode . configOpenApiMode)
|
,("openapi-mode", q . dumpOpenApiMode . configOpenApiMode)
|
||||||
,("openapi-security-active", T.toLower . show . configOpenApiSecurityActive)
|
,("openapi-security-active", T.toLower . show . configOpenApiSecurityActive)
|
||||||
,("openapi-server-proxy-uri", q . fromMaybe mempty . configOpenApiServerProxyUri)
|
,("openapi-server-proxy-uri", q . fromMaybe mempty . configOpenApiServerProxyUri)
|
||||||
@@ -289,7 +280,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
|
|||||||
(optBool "secret-is-base64"))
|
(optBool "secret-is-base64"))
|
||||||
<*> (fromMaybe 1000 <$> optInt "jwt-cache-max-entries")
|
<*> (fromMaybe 1000 <$> optInt "jwt-cache-max-entries")
|
||||||
<*> parseLogLevel "log-level"
|
<*> parseLogLevel "log-level"
|
||||||
<*> parseLogQuery "log-query"
|
<*> (fromMaybe False <$> optBool "log-query")
|
||||||
<*> parseOpenAPIMode "openapi-mode"
|
<*> parseOpenAPIMode "openapi-mode"
|
||||||
<*> (fromMaybe False <$> optBool "openapi-security-active")
|
<*> (fromMaybe False <$> optBool "openapi-security-active")
|
||||||
<*> parseOpenAPIServerProxyURI "openapi-server-proxy-uri"
|
<*> parseOpenAPIServerProxyURI "openapi-server-proxy-uri"
|
||||||
@@ -365,14 +356,6 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
|
|||||||
Just "debug" -> pure LogDebug
|
Just "debug" -> pure LogDebug
|
||||||
Just _ -> fail "Invalid logging level. Check your configuration."
|
Just _ -> fail "Invalid logging level. Check your configuration."
|
||||||
|
|
||||||
parseLogQuery :: C.Key -> C.Parser C.Config LogQuery
|
|
||||||
parseLogQuery k =
|
|
||||||
optString k >>= \case
|
|
||||||
Nothing -> pure LogQueryDisabled
|
|
||||||
Just "disabled" -> pure LogQueryDisabled
|
|
||||||
Just "main-query" -> pure LogQueryMain
|
|
||||||
Just _ -> fail "Invalid SQL logging value. Check your configuration."
|
|
||||||
|
|
||||||
parseTxEnd :: C.Key -> ((Bool, Bool) -> Bool) -> C.Parser C.Config Bool
|
parseTxEnd :: C.Key -> ((Bool, Bool) -> Bool) -> C.Parser C.Config Bool
|
||||||
parseTxEnd k f =
|
parseTxEnd k f =
|
||||||
optString k >>= \case
|
optString k >>= \case
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = true
|
jwt-secret-is-base64 = true
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = true
|
jwt-secret-is-base64 = true
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = true
|
jwt-secret-is-base64 = true
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = "ODERREALLYREALLYREALLYREALLYVERYSAFE"
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 86400
|
jwt-cache-max-entries = 86400
|
||||||
log-level = "info"
|
log-level = "info"
|
||||||
log-query = "main-query"
|
log-query = true
|
||||||
openapi-mode = "disabled"
|
openapi-mode = "disabled"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = "https://otherexample.org/api"
|
openapi-server-proxy-uri = "https://otherexample.org/api"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = "OVERRIDE=REALLY=REALLY=REALLY=REALLY=VERY=SAFE"
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 86400
|
jwt-cache-max-entries = 86400
|
||||||
log-level = "info"
|
log-level = "info"
|
||||||
log-query = "main-query"
|
log-query = true
|
||||||
openapi-mode = "ignore-privileges"
|
openapi-mode = "ignore-privileges"
|
||||||
openapi-security-active = true
|
openapi-security-active = true
|
||||||
openapi-server-proxy-uri = "https://example.org/api"
|
openapi-server-proxy-uri = "https://example.org/api"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5aW5iYXNlNjQ="
|
|||||||
jwt-secret-is-base64 = true
|
jwt-secret-is-base64 = true
|
||||||
jwt-cache-max-entries = 86400
|
jwt-cache-max-entries = 86400
|
||||||
log-level = "info"
|
log-level = "info"
|
||||||
log-query = "main-query"
|
log-query = true
|
||||||
openapi-mode = "ignore-privileges"
|
openapi-mode = "ignore-privileges"
|
||||||
openapi-security-active = true
|
openapi-security-active = true
|
||||||
openapi-server-proxy-uri = "https://postgrest.org"
|
openapi-server-proxy-uri = "https://postgrest.org"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = ""
|
|||||||
jwt-secret-is-base64 = false
|
jwt-secret-is-base64 = false
|
||||||
jwt-cache-max-entries = 1000
|
jwt-cache-max-entries = 1000
|
||||||
log-level = "error"
|
log-level = "error"
|
||||||
log-query = "disabled"
|
log-query = false
|
||||||
openapi-mode = "follow-privileges"
|
openapi-mode = "follow-privileges"
|
||||||
openapi-security-active = false
|
openapi-security-active = false
|
||||||
openapi-server-proxy-uri = ""
|
openapi-server-proxy-uri = ""
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ PGRST_JWT_SECRET: c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5aW5iYXNlNjQ=
|
|||||||
PGRST_JWT_SECRET_IS_BASE64: true
|
PGRST_JWT_SECRET_IS_BASE64: true
|
||||||
PGRST_JWT_CACHE_MAX_ENTRIES: 86400
|
PGRST_JWT_CACHE_MAX_ENTRIES: 86400
|
||||||
PGRST_LOG_LEVEL: info
|
PGRST_LOG_LEVEL: info
|
||||||
PGRST_LOG_QUERY: 'main-query'
|
PGRST_LOG_QUERY: true
|
||||||
PGRST_OPENAPI_MODE: 'ignore-privileges'
|
PGRST_OPENAPI_MODE: 'ignore-privileges'
|
||||||
PGRST_OPENAPI_SECURITY_ACTIVE: true
|
PGRST_OPENAPI_SECURITY_ACTIVE: true
|
||||||
PGRST_OPENAPI_SERVER_PROXY_URI: 'https://postgrest.org'
|
PGRST_OPENAPI_SERVER_PROXY_URI: 'https://postgrest.org'
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5aW5iYXNlNjQ="
|
|||||||
jwt-secret-is-base64 = true
|
jwt-secret-is-base64 = true
|
||||||
jwt-cache-max-entries = 86400
|
jwt-cache-max-entries = 86400
|
||||||
log-level = "info"
|
log-level = "info"
|
||||||
log-query = "main-query"
|
log-query = true
|
||||||
openapi-mode = "ignore-privileges"
|
openapi-mode = "ignore-privileges"
|
||||||
openapi-security-active = true
|
openapi-security-active = true
|
||||||
openapi-server-proxy-uri = "https://postgrest.org"
|
openapi-server-proxy-uri = "https://postgrest.org"
|
||||||
|
|||||||
+1
-1
@@ -1013,7 +1013,7 @@ def test_log_query(level, defaultenv):
|
|||||||
env = {
|
env = {
|
||||||
**defaultenv,
|
**defaultenv,
|
||||||
"PGRST_LOG_LEVEL": level,
|
"PGRST_LOG_LEVEL": level,
|
||||||
"PGRST_LOG_QUERY": "main-query",
|
"PGRST_LOG_QUERY": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
with run(env=env) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import Data.String (String)
|
|||||||
import PostgREST.Config (AppConfig (..),
|
import PostgREST.Config (AppConfig (..),
|
||||||
JSPathExp (..),
|
JSPathExp (..),
|
||||||
LogLevel (..),
|
LogLevel (..),
|
||||||
LogQuery (..),
|
|
||||||
OpenAPIMode (..),
|
OpenAPIMode (..),
|
||||||
parseSecret)
|
parseSecret)
|
||||||
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
|
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
|
||||||
@@ -142,7 +141,7 @@ baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
|
|||||||
, configJwtSecretIsBase64 = False
|
, configJwtSecretIsBase64 = False
|
||||||
, configJwtCacheMaxEntries = 10
|
, configJwtCacheMaxEntries = 10
|
||||||
, configLogLevel = LogCrit
|
, configLogLevel = LogCrit
|
||||||
, configLogQuery = LogQueryDisabled
|
, configLogQuery = False
|
||||||
, configOpenApiMode = OAFollowPriv
|
, configOpenApiMode = OAFollowPriv
|
||||||
, configOpenApiSecurityActive = False
|
, configOpenApiSecurityActive = False
|
||||||
, configOpenApiServerProxyUri = Nothing
|
, configOpenApiServerProxyUri = Nothing
|
||||||
|
|||||||
Reference in New Issue
Block a user