]> git.immae.eu Git - github/fretlink/haskell-graylog.git/blob - src/Graylog/UDP.hs
c925d7ead33d339be0280e02796f0fb1cb9a8da9
[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 Data.ByteString.Builder-}
9 {-import qualified Data.ByteString.Lazy as LBS-}
10 {-import Data.Word-}
11 import Network.Socket.ByteString.Lazy
12 {-import System.Random-}
13
14 import Graylog.Gelf as Export
15 import Graylog.Types as Export
16
17 sendLog :: Graylog -> GELF -> IO ()
18 sendLog glog msg = do
19 _ <- send (_graylogSocket glog) raw
20 print raw
21 return ()
22 where
23 raw = encode msg
24
25 {-sendLog :: Graylog -> GELF -> IO ()-}
26 {-sendLog glog msg = do-}
27 {-cks <- chunky glog raw-}
28 {-mapM_ (send $ _graylogSocket glog) cks-}
29 {-where-}
30 {-raw = encode msg-}
31
32 {-chunky :: Graylog -> LBS.ByteString -> IO [LBS.ByteString]-}
33 {-chunky glog raw = do-}
34 {-groupId <- randomIO-}
35 {-splitAt gsize-}
36 {-where-}
37 {-magic = word8 0x1e <> word8 0x0f-}
38 {-seqNum = undefined-}
39 {-(count, excess) = quotRem (LBS.length raw) gzie-}
40 {-hlen = 12-}
41 {-gsize = (fromIntegral (_graylogChunkSize glog)) - hlen-}