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
|
- #1119, Allow config file reloading with SIGUSR2 - @steve-chavez
|
||||||
- #1558, Allow 'Bearer' with and without capitalization as authentication schema - @wolfgangwalther
|
- #1558, Allow 'Bearer' with and without capitalization as authentication schema - @wolfgangwalther
|
||||||
- #1559, No downtime when reloading the schema cache with SIGUSR1 - @steve-chavez
|
- #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
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ readPathShowHelp = customExecParser parserPrefs opts
|
|||||||
|## content types to produce raw output
|
|## content types to produce raw output
|
||||||
|# raw-media-types="image/png, image/jpg"
|
|# 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"
|
|# log-level = "info"
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@@ -270,6 +270,7 @@ readAppConfig cfgPath = do
|
|||||||
Just "" -> pure LogInfo
|
Just "" -> pure LogInfo
|
||||||
Just "crit" -> pure LogCrit
|
Just "crit" -> pure LogCrit
|
||||||
Just "error" -> pure LogError
|
Just "error" -> pure LogError
|
||||||
|
Just "warn" -> pure LogWarn
|
||||||
Just "info" -> pure LogInfo
|
Just "info" -> pure LogInfo
|
||||||
Just _ -> fail "Invalid logging level. Check your configuration."
|
Just _ -> fail "Invalid logging level. Check your configuration."
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ import Data.Scientific (FPFormat (..),
|
|||||||
isInteger)
|
isInteger)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Hasql.Transaction as H
|
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 Network.Wai.Logger (showSockAddr)
|
||||||
import System.Log.FastLogger (toLogStr)
|
import System.Log.FastLogger (toLogStr)
|
||||||
|
|
||||||
@@ -61,14 +62,14 @@ runPgLocals conf claims app req = do
|
|||||||
anon = JSON.String . toS $ configAnonRole conf
|
anon = JSON.String . toS $ configAnonRole conf
|
||||||
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
preReq = (\f -> "select " <> toS f <> "();") <$> configPreReq conf
|
||||||
|
|
||||||
-- | Log in apache format. Only requests with a failure status.
|
-- | Log in apache format. Only requests that have a status greater than minStatus are logged.
|
||||||
-- | 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.
|
-- | 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 https://github.com/kazu-yamamoto/logger/blob/a4f51b909a099c51af7a3f75cf16e19a06f9e257/wai-logger/Network/Wai/Logger/Apache.hs#L45
|
-- | 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.
|
-- | TODO: Add the ability to filter apache logs on wai-extra and remove this function.
|
||||||
pgrstFormat :: OutputFormatter
|
pgrstFormat :: Status -> OutputFormatter
|
||||||
pgrstFormat date req status responseSize =
|
pgrstFormat minStatus date req status responseSize =
|
||||||
if statusCode status < 400
|
if status < minStatus
|
||||||
then toLogStr BS.empty
|
then mempty
|
||||||
else toLogStr (getSourceFromSocket req)
|
else toLogStr (getSourceFromSocket req)
|
||||||
<> " - - ["
|
<> " - - ["
|
||||||
<> toLogStr date
|
<> toLogStr date
|
||||||
@@ -99,7 +100,8 @@ pgrstMiddleware logLevel =
|
|||||||
where
|
where
|
||||||
logger = case logLevel of
|
logger = case logLevel of
|
||||||
LogCrit -> id
|
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
|
LogInfo -> logStdout
|
||||||
|
|
||||||
defaultCorsPolicy :: CorsResourcePolicy
|
defaultCorsPolicy :: CorsResourcePolicy
|
||||||
|
|||||||
@@ -539,4 +539,4 @@ data ConnectionStatus
|
|||||||
| FatalConnectionError Text
|
| FatalConnectionError Text
|
||||||
deriving (Eq, Show)
|
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