Add warn log level
This commit is contained in:
committed by
Steve Chavez
parent
f6b6abe734
commit
d9a608d9b0
+1
-1
@@ -12,7 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- #1119, Allow config file reloading with SIGUSR2 - @steve-chavez
|
||||
- #1558, Allow 'Bearer' with and without capitalization as authentication schema - @wolfgangwalther
|
||||
- #1559, No downtime when reloading the schema cache with SIGUSR1 - @steve-chavez
|
||||
- #504, Add `log-level` config option - @steve-chavez
|
||||
- #504, Add `log-level` config option. The admitted levels are: crit, error, warn and info - @steve-chavez
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ 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
|
||||
|## logging level, the admitted values are: crit, error, warn and info.
|
||||
|# log-level = "info"
|
||||
|]
|
||||
|
||||
@@ -270,6 +270,7 @@ readAppConfig cfgPath = do
|
||||
Just "" -> pure LogInfo
|
||||
Just "crit" -> pure LogCrit
|
||||
Just "error" -> pure LogError
|
||||
Just "warn" -> pure LogWarn
|
||||
Just "info" -> pure LogInfo
|
||||
Just _ -> fail "Invalid logging level. Check your configuration."
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ import Data.Scientific (FPFormat (..),
|
||||
isInteger)
|
||||
import qualified Data.Text as T
|
||||
import qualified Hasql.Transaction as H
|
||||
import Network.HTTP.Types.Status (statusCode)
|
||||
import Network.HTTP.Types.Status (Status, status400,
|
||||
status500, statusCode)
|
||||
import Network.Wai.Logger (showSockAddr)
|
||||
import System.Log.FastLogger (toLogStr)
|
||||
|
||||
@@ -61,14 +62,14 @@ runPgLocals conf claims app req = do
|
||||
anon = JSON.String . toS $ configAnonRole conf
|
||||
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
||||
|
||||
-- | Log in apache format. Only requests with a failure status.
|
||||
-- | There's no easy way to filter logs in the apache format on https://hackage.haskell.org/package/wai-extra-3.0.29.2/docs/Network-Wai-Middleware-RequestLogger.html#t:OutputFormat.
|
||||
-- | So here we copy https://github.com/kazu-yamamoto/logger/blob/a4f51b909a099c51af7a3f75cf16e19a06f9e257/wai-logger/Network/Wai/Logger/Apache.hs#L45
|
||||
-- | Log in apache format. Only requests that have a status greater than minStatus are logged.
|
||||
-- | There's no way to filter logs in the apache format on wai-extra: https://hackage.haskell.org/package/wai-extra-3.0.29.2/docs/Network-Wai-Middleware-RequestLogger.html#t:OutputFormat.
|
||||
-- | So here we copy wai-logger apacheLogStr function: https://github.com/kazu-yamamoto/logger/blob/a4f51b909a099c51af7a3f75cf16e19a06f9e257/wai-logger/Network/Wai/Logger/Apache.hs#L45
|
||||
-- | TODO: Add the ability to filter apache logs on wai-extra and remove this function.
|
||||
pgrstFormat :: OutputFormatter
|
||||
pgrstFormat date req status responseSize =
|
||||
if statusCode status < 400
|
||||
then toLogStr BS.empty
|
||||
pgrstFormat :: Status -> OutputFormatter
|
||||
pgrstFormat minStatus date req status responseSize =
|
||||
if status < minStatus
|
||||
then mempty
|
||||
else toLogStr (getSourceFromSocket req)
|
||||
<> " - - ["
|
||||
<> toLogStr date
|
||||
@@ -99,7 +100,8 @@ pgrstMiddleware logLevel =
|
||||
where
|
||||
logger = case logLevel of
|
||||
LogCrit -> id
|
||||
LogError -> unsafePerformIO $ mkRequestLogger def { outputFormat = CustomOutputFormat pgrstFormat }
|
||||
LogError -> unsafePerformIO $ mkRequestLogger def { outputFormat = CustomOutputFormat $ pgrstFormat status500}
|
||||
LogWarn -> unsafePerformIO $ mkRequestLogger def { outputFormat = CustomOutputFormat $ pgrstFormat status400}
|
||||
LogInfo -> logStdout
|
||||
|
||||
defaultCorsPolicy :: CorsResourcePolicy
|
||||
|
||||
@@ -539,4 +539,4 @@ data ConnectionStatus
|
||||
| FatalConnectionError Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
data LogLevel = LogCrit | LogError | LogInfo deriving (Eq, Show)
|
||||
data LogLevel = LogCrit | LogError | LogWarn | LogInfo deriving (Eq, Show)
|
||||
|
||||
Reference in New Issue
Block a user