Created
February 15, 2014 08:37
-
-
Save tatac1/9016249 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 | |
, 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