aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Graylog
diff options
context:
space:
mode:
Diffstat (limited to 'src/Graylog')
-rw-r--r--src/Graylog/Gelf.hs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs
index ee17e3d..b6e7ec0 100644
--- a/src/Graylog/Gelf.hs
+++ b/src/Graylog/Gelf.hs
@@ -1,17 +1,20 @@
1{-# LANGUAGE DeriveDataTypeable #-} 1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-} 2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE OverloadedStrings #-} 3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RecordWildCards #-}
4 5
5-- | Default formatting for Graylog messages, 6-- | Default formatting for Graylog messages,
6-- see http://docs.graylog.org/en/latest/pages/gelf.html 7-- see http://docs.graylog.org/en/latest/pages/gelf.html
7module Graylog.Gelf where 8module Graylog.Gelf where
8 9
9import Data.Aeson (ToJSON (..), Value (..), genericToJSON, 10import Data.Aeson (ToJSON (..), Value (..), object,
10 toJSON) 11 toJSON, (.=))
11import Data.Aeson.Casing 12import Data.HashMap.Strict (HashMap)
12import Data.Text (Text) 13import Data.Semigroup ((<>))
14import Data.Text (Text)
13import Data.Time 15import Data.Time
14import Data.Typeable 16import Data.Typeable
17import GHC.Exts (toList)
15import GHC.Generics 18import GHC.Generics
16 19
17data GELF 20data GELF
@@ -24,11 +27,20 @@ data GELF
24 , _gelfLevel :: Maybe SyslogLevel 27 , _gelfLevel :: Maybe SyslogLevel
25 , _gelfLine :: Maybe Word 28 , _gelfLine :: Maybe Word
26 , _gelfFile :: Maybe Text 29 , _gelfFile :: Maybe Text
30 , _gelfMeta :: HashMap Text Text
27 } 31 }
28 deriving (Show, Typeable, Generic) 32 deriving (Show, Typeable, Generic)
29 33
30instance ToJSON GELF where 34instance ToJSON GELF where
31 toJSON = genericToJSON $ aesonPrefix snakeCase 35 toJSON GELF{..} = object $ [ "version" .= _gelfVersion
36 , "host" .= _gelfHost
37 , "short_message" .= _gelfShortMessage
38 , "full_message" .= _gelfFullMessage
39 , "timestamp" .= _gelfTimestamp
40 , "level" .= _gelfLevel
41 , "line" .= _gelfLine
42 , "file" .= _gelfFile
43 ] <> toList (String <$> _gelfMeta)
32 44
33-- 45--
34 46
@@ -69,4 +81,4 @@ simpleGelf
69 -> Text -- ^ Short message 81 -> Text -- ^ Short message
70 -> GELF 82 -> GELF
71simpleGelf host short = 83simpleGelf host short =
72 GELF Version1x1 host short Nothing Nothing Nothing Nothing Nothing 84 GELF Version1x1 host short Nothing Nothing Nothing Nothing Nothing mempty