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