]> git.immae.eu Git - github/fretlink/haskell-graylog.git/blob - src/Graylog/UDP.hs
Framed UDP function.
[github/fretlink/haskell-graylog.git] / src / Graylog / UDP.hs
1 module Graylog.UDP
2 ( sendLog
3
4 , module Export
5 ) where
6
7 import Data.Aeson
8 import qualified Data.ByteString.Lazy as LBS
9 import Data.Word
10 import Network.Socket.ByteString.Lazy
11 import System.Random
12
13 import Graylog.Gelf as Export
14 import Graylog.Types as Export
15
16 sendLog :: Graylog -> GELF -> IO ()
17 sendLog glog msg = mapM_ (send $ _graylogSocket glog) cks
18 where
19 raw = encode msg
20 cks = chunky glog raw
21
22 chunky :: Graylog -> LBS.ByteString -> IO [LBS.ByteString]
23 chunky glog raw = do
24 groupId <- randomIO
25 splitAt gsize
26 where
27 magic = undefined
28 seq = undefined
29 total = undefined
30 hlen = 12
31 gsize = (fromIntegral (_graylogChunkSize glog)) - hlen