Logging

I saw the logging code commented in the sample project, seems the only thing missing is a simple remote logging server.

RemoteLog.hs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Network
import Prelude ()
import Control.Monad
import System.IO
import MPS.Env

main :: IO ()
main = do

let port = 4242
puts = putStrLn

puts - "listening on port: " ++ port.show

socket <- listenOn - PortNumber port

forever - do
(h, _, _) <- accept socket

hGetLine h >>= puts
hClose h

Main.hs

1
2
3
4
5
6
7
8
9
10
openLogger :: IO Handle
openLogger = do
log <- connectTo "127.0.0.1" (PortNumber 4242)
hSetBuffering log LineBuffering
return log

log :: String -> IO ()
log x = do
hLog <- openLogger
hPutStrLn hLog x
1
2
main = do
log "init main ..."
blog comments powered by Disqus