Skip to content

Instantly share code, notes, and snippets.

@tatac1
Created February 15, 2014 08:37
Show Gist options
  • Save tatac1/9016249 to your computer and use it in GitHub Desktop.
Save tatac1/9016249 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings
, FlexibleContexts
, ScopedTypeVariables #-}
import ParsecRFC3164
import Data.Conduit.Network
import Data.Conduit
import Data.Conduit.Binary
import Data.ByteString (ByteString)
import Control.Monad.IO.Class
import qualified Data.Conduit.Attoparsec as AC
import qualified Data.ByteString.Char8 as B8
app :: (Monad m, MonadIO m, MonadResource m) => AppData m -> m ()
app stream = appSource stream $$ takeSyslog =$ sinkFile "./out.txt"
takeSyslog :: (Monad m, MonadIO m, MonadResource m) => Conduit ByteString m ByteString
takeSyslog = AC.conduitParserEither parseRFC3164 =$= awaitForever go
where
go (Left s) = error $ show s
go (Right (_, parsedMsg)) = yield $ B8.pack $ show parsedMsg ++ "\n"
main :: IO ()
main = runResourceT $ runTCPServer (serverSettings 10514 HostAny) app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment