Skip to content

Commit

Permalink
chore: add log-level=debug
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Apr 22, 2024
1 parent 1bf0c54 commit 0fe9c71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/PostgREST/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ data AppConfig = AppConfig
, configInternalSCSleep :: Maybe Int32
}

data LogLevel = LogCrit | LogError | LogWarn | LogInfo
data LogLevel = LogCrit | LogError | LogWarn | LogInfo | LogDebug
deriving (Eq, Ord)

dumpLogLevel :: LogLevel -> Text
Expand All @@ -123,6 +123,7 @@ dumpLogLevel = \case
LogError -> "error"
LogWarn -> "warn"
LogInfo -> "info"
LogDebug -> "debug"

Check warning on line 126 in src/PostgREST/Config.hs

View check run for this annotation

Codecov / codecov/patch

src/PostgREST/Config.hs#L126

Added line #L126 was not covered by tests

data OpenAPIMode = OAFollowPriv | OAIgnorePriv | OADisabled
deriving Eq
Expand Down Expand Up @@ -338,6 +339,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
Just "error" -> pure LogError
Just "warn" -> pure LogWarn
Just "info" -> pure LogInfo
Just "debug" -> pure LogDebug

Check warning on line 342 in src/PostgREST/Config.hs

View check run for this annotation

Codecov / codecov/patch

src/PostgREST/Config.hs#L342

Added line #L342 was not covered by tests
Just _ -> fail "Invalid logging level. Check your configuration."

parseTxEnd :: C.Key -> ((Bool, Bool) -> Bool) -> C.Parser C.Config Bool
Expand Down
10 changes: 7 additions & 3 deletions src/PostgREST/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ logWithDebounce loggerState action = do

middleware :: LogLevel -> (Wai.Request -> Maybe BS.ByteString) -> Wai.Middleware
middleware logLevel getAuthRole = case logLevel of
LogInfo -> requestLogger (const True)
LogWarn -> requestLogger (>= status400)
LogError -> requestLogger (>= status500)
LogCrit -> requestLogger (const False)
LogError -> requestLogger (>= status500)
LogWarn -> requestLogger (>= status400)
LogInfo -> requestLogger (const True)
LogDebug -> requestLogger (const True)

Check warning on line 63 in src/PostgREST/Logger.hs

View check run for this annotation

Codecov / codecov/patch

src/PostgREST/Logger.hs#L63

Added line #L63 was not covered by tests
where
requestLogger filterStatus = unsafePerformIO $
Wai.mkRequestLogger Wai.defaultRequestLoggerSettings
Expand All @@ -84,6 +85,9 @@ observationLogger loggerState logLevel obs = case obs of
o@(HasqlPoolObs _) -> do
when (logLevel >= LogInfo) $ do
logWithZTime loggerState $ observationMessage o
o@(SchemaCacheLoadedObs _) -> do
when (logLevel >= LogDebug) $ do
logWithZTime loggerState $ observationMessage o

Check warning on line 90 in src/PostgREST/Logger.hs

View check run for this annotation

Codecov / codecov/patch

src/PostgREST/Logger.hs#L90

Added line #L90 was not covered by tests
o ->
logWithZTime loggerState $ observationMessage o

Expand Down

0 comments on commit 0fe9c71

Please sign in to comment.