]>
Commit | Line | Data |
---|---|---|
15981d57 | 1 | module Graylog.UDP |
c91dbdc0 | 2 | ( sendLog |
15981d57 | 3 | |
2ff46fce | 4 | , module Export |
15981d57 A |
5 | ) where |
6 | ||
c91dbdc0 | 7 | import Data.Aeson |
b23afe7b A |
8 | {-import Data.ByteString.Builder-} |
9 | {-import qualified Data.ByteString.Lazy as LBS-} | |
10 | {-import Data.Word-} | |
c91dbdc0 | 11 | import Network.Socket.ByteString.Lazy |
b23afe7b | 12 | {-import System.Random-} |
c91dbdc0 A |
13 | |
14 | import Graylog.Gelf as Export | |
15 | import Graylog.Types as Export | |
15981d57 A |
16 | |
17 | sendLog :: Graylog -> GELF -> IO () | |
b23afe7b A |
18 | sendLog glog msg = do |
19 | _ <- send (_graylogSocket glog) raw | |
20 | print raw | |
21 | return () | |
c91dbdc0 A |
22 | where |
23 | raw = encode msg | |
2ff46fce | 24 | |
b23afe7b A |
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-} |