diff options
author | Thomas Crevoisier <thomas.crevoisier@fretlink.com> | 2018-11-30 17:01:18 +0100 |
---|---|---|
committer | Thomas Crevoisier <thomas.crevoisier@fretlink.com> | 2018-11-30 17:04:41 +0100 |
commit | 4b6637800bf7813570cf7a628794a0351835711b (patch) | |
tree | 6f4bb1ef345f3db21c004bc11391da5a0c26767c /src/Graylog | |
parent | 8c9d965d06998aeb9474742c0923feb36a6fc636 (diff) | |
download | haskell-graylog-4b6637800bf7813570cf7a628794a0351835711b.tar.gz haskell-graylog-4b6637800bf7813570cf7a628794a0351835711b.tar.zst haskell-graylog-4b6637800bf7813570cf7a628794a0351835711b.zip |
Allow sending numbers in additional fieldssupport-additional-meta
Diffstat (limited to 'src/Graylog')
-rw-r--r-- | src/Graylog/Gelf.hs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs index b6e7ec0..8ffe24f 100644 --- a/src/Graylog/Gelf.hs +++ b/src/Graylog/Gelf.hs | |||
@@ -7,9 +7,10 @@ | |||
7 | -- see http://docs.graylog.org/en/latest/pages/gelf.html | 7 | -- see http://docs.graylog.org/en/latest/pages/gelf.html |
8 | module Graylog.Gelf where | 8 | module Graylog.Gelf where |
9 | 9 | ||
10 | import Data.Aeson (ToJSON (..), Value (..), object, | 10 | import Data.Aeson (ToJSON (..), Value (..), object, toJSON, |
11 | toJSON, (.=)) | 11 | (.=)) |
12 | import Data.HashMap.Strict (HashMap) | 12 | import Data.HashMap.Strict (HashMap) |
13 | import Data.Scientific (Scientific) | ||
13 | import Data.Semigroup ((<>)) | 14 | import Data.Semigroup ((<>)) |
14 | import Data.Text (Text) | 15 | import Data.Text (Text) |
15 | import Data.Time | 16 | import Data.Time |
@@ -27,10 +28,34 @@ data GELF | |||
27 | , _gelfLevel :: Maybe SyslogLevel | 28 | , _gelfLevel :: Maybe SyslogLevel |
28 | , _gelfLine :: Maybe Word | 29 | , _gelfLine :: Maybe Word |
29 | , _gelfFile :: Maybe Text | 30 | , _gelfFile :: Maybe Text |
30 | , _gelfMeta :: HashMap Text Text | 31 | , _gelfMeta :: HashMap Text MetaValue |
31 | } | 32 | } |
32 | deriving (Show, Typeable, Generic) | 33 | deriving (Show, Typeable, Generic) |
33 | 34 | ||
35 | data MetaValue | ||
36 | = TextValue Text | ||
37 | | NumberValue Scientific | ||
38 | deriving (Show) | ||
39 | |||
40 | instance ToJSON MetaValue where | ||
41 | toJSON (TextValue txt) = toJSON txt | ||
42 | toJSON (NumberValue n) = toJSON n | ||
43 | |||
44 | class ToMeta a where | ||
45 | toMeta :: a -> MetaValue | ||
46 | |||
47 | instance ToMeta Text where | ||
48 | toMeta = TextValue | ||
49 | |||
50 | instance ToMeta Scientific where | ||
51 | toMeta = NumberValue | ||
52 | |||
53 | instance ToMeta Integer where | ||
54 | toMeta = NumberValue . fromInteger | ||
55 | |||
56 | instance ToMeta Int where | ||
57 | toMeta = toMeta . toInteger | ||
58 | |||
34 | instance ToJSON GELF where | 59 | instance ToJSON GELF where |
35 | toJSON GELF{..} = object $ [ "version" .= _gelfVersion | 60 | toJSON GELF{..} = object $ [ "version" .= _gelfVersion |
36 | , "host" .= _gelfHost | 61 | , "host" .= _gelfHost |
@@ -40,7 +65,7 @@ instance ToJSON GELF where | |||
40 | , "level" .= _gelfLevel | 65 | , "level" .= _gelfLevel |
41 | , "line" .= _gelfLine | 66 | , "line" .= _gelfLine |
42 | , "file" .= _gelfFile | 67 | , "file" .= _gelfFile |
43 | ] <> toList (String <$> _gelfMeta) | 68 | ] <> toList (toJSON <$> _gelfMeta) |
44 | 69 | ||
45 | -- | 70 | -- |
46 | 71 | ||