-Copyright (c) 2016 Andrew Rademacher
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+ Copyright (C) 2016 Andrew Rademacher <andrewrademacher@gmail.com>
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
--- /dev/null
+# Graylog
+This library provides support for sending GELF formatted messages to Graylog.
+Currently the UDP chunked method is the only method supported.
+
+```haskell
+import Graylog.UDP
+
+main :: IO ()
+main = do
+ eglog <- openGraylog "192.168.99.100" "12201" defaultChunkSize
+ case eglog of
+ Left e -> assertFailure e
+ Right g -> sendLog g sample >> closeGraylog g
+ where
+ sample = simpleGelf "localhost" "hello world!"
+```
name: graylog
version: 0.1.0.0
synopsis: Support for graylog output.
-description: Please see README.md
-homepage: http://github.com/githubuser/graylog#readme
-license: MIT
+description: Support for sending GELF formatted messages to graylog over
+ chunked UDP.
+homepage: https://github.com/AndrewRademacher/haskell-graylog
+license: WTFPL
license-file: LICENSE
author: Andrew Rademacher
maintainer: andrewrademacher@gmail.com
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
+-- | Default formatting for Graylog messages,
+-- see http://docs.graylog.org/en/latest/pages/gelf.html
module Graylog.Gelf where
import Data.Aeson (ToJSON (..), Value (..), genericToJSON,
import Network.BSD
import Network.Socket
+-- | The maximum size of each datagram when using UDP transit methods.
type ChunkSize = Word
+-- | Handle for a socket connected to Graylog. In some cases this socket
+-- is UDP and will not have a maintained session.
data Graylog
= Graylog
{ _graylogHost :: String
defaultChunkSize = 8192
openGraylog
- :: HostName -> ServiceName -> ChunkSize -> IO (Either String Graylog)
+ :: HostName -- ^ The host on which graylog is running.
+ -> ServiceName -- ^ The port on which graylog is running.
+ -> ChunkSize -- ^ The maximum size of each UDP datagram.
+ -> IO (Either String Graylog)
openGraylog h p cksize
| cksize < 1024 = return $ Left "ChunkSize must be at least 1024."
| otherwise = getAddrInfo Nothing (Just h) (Just p) >>= \case