Skip to content

Commit

Permalink
Make http logging optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Sideris committed Feb 8, 2021
1 parent 25f1232 commit 433068c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ services:
HAKA_SESSION_EXPIRY: "24"
HAKA_LOG_LEVEL: "info" # Control the verbosity of the logger.
HAKA_ENV: "prod" # Use a json logger for production, otherwise key=value pairs.
HAKA_HTTP_LOG: "true" # If you want to log http requests.
ports:
- "127.0.0.1:8080:8080"
haka_db:
Expand Down
12 changes: 9 additions & 3 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ initApp settings unApp = do
threadDelay 1000000
)

withStdoutLogger $ \logger -> do
let conf = setPort (hakaPort settings) $ setLogger logger defaultSettings
runSettings conf (unApp appCtx)
if hakaHasHttpLogger settings
then do
withStdoutLogger $ \logger -> do
let conf = setPort (hakaPort settings) $ setLogger logger defaultSettings
runSettings conf (unApp appCtx)
else do
run (hakaPort settings) (unApp appCtx)

getServerSettings :: IO ServerSettings
getServerSettings = do
Expand All @@ -102,6 +106,7 @@ getServerSettings = do
sessionExpiry <- envAsInt "HAKA_SESSION_EXPIRY" 24
logLevel <- envAsString "HAKA_LOG_LEVEL" "info"
rEnv <- envAsString "HAKA_ENV" "prod"
enableHttpLog <- envAsBool "HAKA_HTTP_LOG" True
when (sessionExpiry <= 0) (error "Session expiry should be a positive integer")
return $
ServerSettings
Expand All @@ -111,6 +116,7 @@ getServerSettings = do
hakaDashboardPath = dashboardPath,
hakaShieldsIOUrl = shieldsIOUrl,
hakaLogLevel = logLevel,
hakaHasHttpLogger = enableHttpLog,
hakaRunEnv = case rEnv of
"prod" -> Log.Prod
"production" -> Log.Prod
Expand Down
1 change: 1 addition & 0 deletions docker-compose-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
HAKA_SESSION_EXPIRY: "24"
HAKA_LOG_LEVEL: "info" # Control the verbosity of the logger.
HAKA_ENV: "prod" # Use a json logger for production.
HAKA_HTTP_LOG: "true" # If you want to log http requests.
ports:
- "127.0.0.1:8080:8080"
haka_db:
Expand Down
4 changes: 3 additions & 1 deletion src/Haka/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,7 @@ data ServerSettings = ServerSettings
-- | Control the logger output format. json for prod, key-value pair for dev.
hakaRunEnv :: Log.EnvType,
-- | Verbosity level.
hakaLogLevel :: String
hakaLogLevel :: String,
-- | Whether to log the HTTP requests.
hakaHasHttpLogger :: Bool
}

0 comments on commit 433068c

Please sign in to comment.