Giter Club home page Giter Club logo

Comments (6)

kazu-yamamoto avatar kazu-yamamoto commented on August 11, 2024

What is wai_logger.hs? The link refers to code in wai-logger which I think is correct.

from logger.

ericsagnes avatar ericsagnes commented on August 11, 2024

Sorry for not being precise, wai_logger.hs is the code from the example:

wai_logger.hs:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Blaze.ByteString.Builder (fromByteString)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Char8 as BS
import Network.HTTP.Types (status200)
import Network.Wai (Application, responseBuilder)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Logger (withStdoutLogger, ApacheLogger)

main :: IO ()
main = withStdoutLogger $ \aplogger ->
    run 3000 $ logApp aplogger

logApp :: ApacheLogger -> Application
logApp aplogger req = do
    liftIO $ aplogger req status (Just len)
    return $ responseBuilder status hdr msg
  where
    status = status200
    hdr = [("Content-Type", "text/plain")
          ,("Content-Length", BS.pack (show len))]
    pong = "PONG"
    len = fromIntegral $ BS.length pong
    msg = toLogStr pong

from logger.

kazu-yamamoto avatar kazu-yamamoto commented on August 11, 2024

Ah, thanks. You refer to the example in the manual (http://hackage.haskell.org/package/wai-logger-2.2.4/docs/Network-Wai-Logger.html).
I understand the problem. Please wait.

from logger.

kazu-yamamoto avatar kazu-yamamoto commented on August 11, 2024

Here is a fixed version. I will replace the example.

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Blaze.ByteString.Builder (fromByteString)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Char8 as BS
import Network.HTTP.Types (status200)
import Network.Wai (Application, responseBuilder)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Logger (withStdoutLogger, ApacheLogger)

main :: IO ()
main = withStdoutLogger $ \aplogger ->
    run 3000 $ logApp aplogger

logApp :: ApacheLogger -> Application
logApp aplogger req response = do
    liftIO $ aplogger req status (Just len)
    response $ responseBuilder status hdr msg
  where
    status = status200
    hdr = [("Content-Type", "text/plain")]
    pong = "PONG"
    msg = fromByteString pong
    len = fromIntegral $ BS.length pong

from logger.

kazu-yamamoto avatar kazu-yamamoto commented on August 11, 2024

I have released a new version of wai-logger.

from logger.

ericsagnes avatar ericsagnes commented on August 11, 2024

Thanks! It works perfectly.

from logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.