1 -- | UDP Chunked support for sending messages to graylog.
9 import Data.ByteString.Builder
10 import qualified Data.ByteString.Lazy as LBS
13 import Network.Socket.ByteString.Lazy
16 import Graylog.Gelf as Export
17 import Graylog.Types as Export
19 sendLog :: Graylog -> GELF -> IO ()
21 cks <- chunky glog raw
22 mapM_ (send $ _graylogSocket glog) cks
26 chunky :: Graylog -> LBS.ByteString -> IO [LBS.ByteString]
29 let groups = divide totalNum raw
30 return $ append groupId groups seqNums
32 magic = word8 0x1e <> word8 0x0f
33 seqNums = [0..] :: [Word8]
34 totalNum = if excess > 0 then count + 1 else count
35 (count, excess) = quotRem (LBS.length raw) gsize
37 gsize = (fromIntegral (_graylogChunkSize glog)) - hlen
40 divide num dat = let (pre, post) = LBS.splitAt gsize dat
41 in pre : divide (num - 1) post
44 append _ _ [] = error "the impossible has happened."
45 append gid (g:gs) (s:ss) = (toLazyByteString
49 <> word8 (fromIntegral totalNum)
50 <> lazyByteString g) : append gid gs ss