Blammo-wai: Using Blammo with WAI

[ library, logging, mit, web ] [ Propose Tags ] [ Report a vulnerability ]

Please see README.md


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.0, 0.0.0.1, 0.0.0.2
Change log CHANGELOG.md
Dependencies aeson (>=1.5.2.0), base (>=4.13.0.0 && <5), Blammo (>=2.1.0.0), bytestring (>=0.10.10.1), case-insensitive (>=1.2.1.0), clock (>=0.8), http-types (>=0.12.3), monad-logger-aeson (>=0.4.0.3), text (>=1.2.4.0), unliftio-core (>=0.1.2.0), wai (>=3.2.2.1) [details]
License MIT
Author
Maintainer Freckle Education
Category Logging, Web
Home page https://github.com/freckle/blammo#readme
Bug tracker https://github.com/freckle/blammo/issues
Source repo head: git clone https://github.com/freckle/blammo
Uploaded by PatrickBrisbin at 2024-08-01T22:40:06Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 136 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-08-01 [all 1 reports]

Readme for Blammo-wai-0.0.0.2

[back to package description]

Blammo-wai

Integration of Blammo with wai.

-- Blammo
import Blammo.Logging.Simple

-- wai
import Network.Wai (Middleware)

-- Blammo-wai
import Network.Wai.Middleware.Logging

-- warp
import qualified Network.Wai.Handler.Warp as Warp

-- yesod
import Yesod.Core (Yesod)
import qualified Yesod.Core as Yesod
data App = App
  { appLogger :: Logger
  -- etc.
  }

instance HasLogger App where
  loggerL = lens appLogger $ \x y -> x {appLogger = y}

Integration with WAI

waiMiddleware :: App -> Middleware
waiMiddleware app =
  addThreadContext ["app" .= ("my-app" :: Text)]
    . requestLogger app
    . Yesod.defaultMiddlewaresNoLogging

Integration with Warp

warpSettings :: App -> Warp.Settings
warpSettings app = Warp.setOnException onEx $ Warp.defaultSettings
 where
  onEx _req ex =
    when (Warp.defaultShouldDisplayException ex)
      $ runWithLogger app
      $ logError
      $ "Warp exception" :# ["exception" .= displayException ex]

Integration with Yesod

instance Yesod App where
  messageLoggerSource app _logger loc source level msg =
    runWithLogger app $ monadLoggerLog loc source level msg