3

I have a simple hello world happstack app:

module Main where

import Happstack.Server (nullConf, simpleHTTP, toResponse, ok)

main :: IO ()
main = simpleHTTP nullConf $ ok "Hello, World!"

I want it to log requests to stdout.

I found this http://happstack.wordpress.com/2009/02/26/happstack-now-outputs-apache-combined-logs/ which says it is outputting logs, but they are not going to stdout. I've never used hslogger before and am having trouble figuring how to a) configure it, and b) wire it into happstack. nullConf provides a default logMAccess, but it isn't clear how that ends up in hslogger.

Xavier Shay
  • 4,067
  • 1
  • 30
  • 54

1 Answers1

3

Just after I posted I found this: http://www.haskell.org/pipermail/beginners/2011-August/008184.html which gave me the clue I needed.

module Main where

import Happstack.Server (nullConf, simpleHTTP, toResponse, ok)

import System.IO
import System.Log.Logger ( updateGlobalLogger
                         , rootLoggerName
                         , setLevel
                         , Priority(..)
                         )

main :: IO ()
main = do
  updateGlobalLogger rootLoggerName (setLevel INFO)

  simpleHTTP nullConf $ ok "Hello, World!"
Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
  • You probably do not want to change the root logger settings—it changes the behavior for _all_ children—but only "Happstack"'s – Matvey Aksenov Feb 12 '14 at 18:15
  • To make this absolutely clear, as this is one of very few google-hits on this subject. There is one more import that is needed to enable Happstack's default accesslog: `import System.Log.Handler.Simple` – user532954 Oct 27 '15 at 10:13