Created
June 26, 2013 09:31
-
-
Save tatac1/5866101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Control.Monad.Trans.Class (lift) | |
import Control.Monad.IO.Class | |
import Control.Monad.Trans.Control () | |
import Data.Conduit | |
import Data.Conduit.Network | |
import Data.Conduit.Attoparsec | |
import Data.Attoparsec.ByteString | |
import Control.Concurrent (forkIO) | |
import qualified Data.Conduit.List as CL | |
import qualified Data.Conduit.Binary as CB | |
import qualified Data.ByteString.Char8 as BS | |
import qualified Control.Exception.Lifted as E | |
import ParsecRFC3164 | |
app :: (MonadIO m, MonadThrow m, MonadBaseControl IO m) => Application m | |
app ad = E.handle erroHandler $ appSource ad | |
$$ CB.lines | |
=$ parseMsg | |
parseMsg :: (MonadThrow m, MonadIO m, MonadBaseControl IO m) => Consumer BS.ByteString m () | |
parseMsg = do | |
mstr <- await | |
case mstr of | |
Nothing -> return () | |
Just str -> do | |
liftIO $ print str | |
parseMsg | |
erroHandler :: (MonadBaseControl IO m) => ParseError -> m () | |
erroHandler _ = return () | |
main :: IO () | |
main = runTCPServer (serverSettings 10514 HostAny) app | |
takeSyslog :: (Monad m, MonadThrow m) => Conduit BS.ByteString m RFC3164 | |
takeSyslog = CL.sequence $ sinkParser parseRFC3164 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment