Skip to content

Commit 09b088d

Browse files
committed
change: change log-query string value to bool
BREAKING CHANGE As discussed on #3934 (comment), this changes log-query to use a bool value, this: - Simplifies config for users. - Reduces effort in testing the different combinations. Closes #3934
1 parent e4458ab commit 09b088d

22 files changed

+28
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2121

2222
- Drop support for PostgreSQL EOL version 12 by @wolfgangwalther in #3865
2323
- Replaced `jwt-cache-max-lifetime` config with `jwt-cache-max-entries` by @mkleczek in #4084
24+
- `log-query` config now takes a boolean instead of a string value by @steve-chavez in #3934
2425

2526
## [13.0.7] - 2025-09-14
2627

docs/references/configuration.rst

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,23 +714,14 @@ log-query
714714
---------
715715

716716
=============== =================================
717-
**Type** String
718-
**Default** "disabled"
717+
**Type** Boolean
718+
**Default** False
719719
**Reloadable** Y
720720
**Environment** PGRST_LOG_QUERY
721721
**In-Database** `n/a`
722722
=============== =================================
723723

724-
Logs the SQL query for the corresponding request at the current :ref:`log-level`.
725-
See :ref:`sql_query_logs`.
726-
727-
.. code:: bash
728-
729-
# Logs the main SQL query
730-
log-query = "main-query"
731-
732-
# Disables logging the SQL query
733-
log-query = "disabled"
724+
Logs the SQL query for the corresponding request at the current :ref:`log-level`. See :ref:`sql_query_logs`.
734725

735726
.. _openapi-mode:
736727

docs/references/observability.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ For diagnostic information about the server itself, PostgREST logs to ``stderr``
5252
SQL Query Logs
5353
--------------
5454

55-
To log the :ref:`main SQL query <main_query>` executed for a request, set the :ref:`log-query` to ``main-query``.
56-
It will be logged based on the current :ref:`log-level` setting.
57-
For example, with this configuration:
55+
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.
5856

5957
.. code-block:: bash
6058
6159
log-level = "warn"
62-
log-query = "main-query"
60+
log-query = "true"
6361
6462
The SQL queries will only be logged on ``400`` HTTP errors and up.
6563
So, if the user requests a resource without sufficient privileges:

src/PostgREST/App.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ import qualified PostgREST.Unix as Unix (installSignalHandlers)
4444
import PostgREST.ApiRequest (ApiRequest (..))
4545
import PostgREST.AppState (AppState)
4646
import PostgREST.Auth.Types (AuthResult (..))
47-
import PostgREST.Config (AppConfig (..), LogLevel (..),
48-
LogQuery (..))
47+
import PostgREST.Config (AppConfig (..), LogLevel (..))
4948
import PostgREST.Error (Error)
5049
import PostgREST.Network (resolveSocketToAddress)
5150
import PostgREST.Observation (Observation (..))
@@ -146,7 +145,7 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache authResult@AuthRe
146145
let mainQ = Query.mainQuery plan conf apiReq authResult configDbPreRequest
147146
tx = MainTx.mainTx mainQ conf authResult apiReq plan sCache
148147
observer = AppState.getObserver appState
149-
obsQuery s = when (configLogQuery /= LogQueryDisabled) $ observer $ QueryObs mainQ s
148+
obsQuery s = when configLogQuery $ observer $ QueryObs mainQ s
150149

151150
(txTime, txResult) <- withTiming $ do
152151
case tx of

src/PostgREST/Config.hs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module PostgREST.Config
1717
, JSPathExp(..)
1818
, FilterExp(..)
1919
, LogLevel(..)
20-
, LogQuery(..)
2120
, OpenAPIMode(..)
2221
, Proxy(..)
2322
, toText
@@ -99,7 +98,7 @@ data AppConfig = AppConfig
9998
, configJwtSecretIsBase64 :: Bool
10099
, configJwtCacheMaxEntries :: Int
101100
, configLogLevel :: LogLevel
102-
, configLogQuery :: LogQuery
101+
, configLogQuery :: Bool
103102
, configOpenApiMode :: OpenAPIMode
104103
, configOpenApiSecurityActive :: Bool
105104
, configOpenApiServerProxyUri :: Maybe Text
@@ -128,14 +127,6 @@ dumpLogLevel = \case
128127
LogInfo -> "info"
129128
LogDebug -> "debug"
130129

131-
data LogQuery = LogQueryMain | LogQueryDisabled
132-
deriving (Eq)
133-
134-
dumpLogQuery :: LogQuery -> Text
135-
dumpLogQuery = \case
136-
LogQueryMain -> "main-query"
137-
LogQueryDisabled -> "disabled"
138-
139130
data OpenAPIMode = OAFollowPriv | OAIgnorePriv | OADisabled
140131
deriving Eq
141132

@@ -179,7 +170,7 @@ toText conf =
179170
,("jwt-secret-is-base64", T.toLower . show . configJwtSecretIsBase64)
180171
,("jwt-cache-max-entries", show . configJwtCacheMaxEntries)
181172
,("log-level", q . dumpLogLevel . configLogLevel)
182-
,("log-query", q . dumpLogQuery . configLogQuery)
173+
,("log-query", T.toLower . show . configLogQuery)
183174
,("openapi-mode", q . dumpOpenApiMode . configOpenApiMode)
184175
,("openapi-security-active", T.toLower . show . configOpenApiSecurityActive)
185176
,("openapi-server-proxy-uri", q . fromMaybe mempty . configOpenApiServerProxyUri)
@@ -289,7 +280,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
289280
(optBool "secret-is-base64"))
290281
<*> (fromMaybe 1000 <$> optInt "jwt-cache-max-entries")
291282
<*> parseLogLevel "log-level"
292-
<*> parseLogQuery "log-query"
283+
<*> (fromMaybe False <$> optBool "log-query")
293284
<*> parseOpenAPIMode "openapi-mode"
294285
<*> (fromMaybe False <$> optBool "openapi-security-active")
295286
<*> parseOpenAPIServerProxyURI "openapi-server-proxy-uri"
@@ -365,14 +356,6 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
365356
Just "debug" -> pure LogDebug
366357
Just _ -> fail "Invalid logging level. Check your configuration."
367358

368-
parseLogQuery :: C.Key -> C.Parser C.Config LogQuery
369-
parseLogQuery k =
370-
optString k >>= \case
371-
Nothing -> pure LogQueryDisabled
372-
Just "disabled" -> pure LogQueryDisabled
373-
Just "main-query" -> pure LogQueryMain
374-
Just _ -> fail "Invalid SQL logging value. Check your configuration."
375-
376359
parseTxEnd :: C.Key -> ((Bool, Bool) -> Bool) -> C.Parser C.Config Bool
377360
parseTxEnd k f =
378361
optString k >>= \case

test/io/configs/expected/aliases.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jwt-secret = ""
2525
jwt-secret-is-base64 = true
2626
jwt-cache-max-entries = 1000
2727
log-level = "error"
28-
log-query = "disabled"
28+
log-query = false
2929
openapi-mode = "follow-privileges"
3030
openapi-security-active = false
3131
openapi-server-proxy-uri = ""

test/io/configs/expected/boolean-numeric.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jwt-secret = ""
2525
jwt-secret-is-base64 = true
2626
jwt-cache-max-entries = 1000
2727
log-level = "error"
28-
log-query = "disabled"
28+
log-query = false
2929
openapi-mode = "follow-privileges"
3030
openapi-security-active = false
3131
openapi-server-proxy-uri = ""

test/io/configs/expected/boolean-string.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jwt-secret = ""
2525
jwt-secret-is-base64 = true
2626
jwt-cache-max-entries = 1000
2727
log-level = "error"
28-
log-query = "disabled"
28+
log-query = false
2929
openapi-mode = "follow-privileges"
3030
openapi-security-active = false
3131
openapi-server-proxy-uri = ""

test/io/configs/expected/defaults.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jwt-secret = ""
2525
jwt-secret-is-base64 = false
2626
jwt-cache-max-entries = 1000
2727
log-level = "error"
28-
log-query = "disabled"
28+
log-query = false
2929
openapi-mode = "follow-privileges"
3030
openapi-security-active = false
3131
openapi-server-proxy-uri = ""

test/io/configs/expected/jwt-role-claim-key1.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jwt-secret = ""
2525
jwt-secret-is-base64 = false
2626
jwt-cache-max-entries = 1000
2727
log-level = "error"
28-
log-query = "disabled"
28+
log-query = false
2929
openapi-mode = "follow-privileges"
3030
openapi-security-active = false
3131
openapi-server-proxy-uri = ""

0 commit comments

Comments
 (0)