aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 16:52:14 -0600
committerAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 16:52:14 -0600
commit526966434f2248c1200427677dc3882668714693 (patch)
treeaa4fb861b90abf2ee444465443afe9aa375abddf /src
downloadhaskell-graylog-526966434f2248c1200427677dc3882668714693.tar.gz
haskell-graylog-526966434f2248c1200427677dc3882668714693.tar.zst
haskell-graylog-526966434f2248c1200427677dc3882668714693.zip
Project init; added Gelf format.
Diffstat (limited to 'src')
-rw-r--r--src/Graylog/Gelf.hs76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs
new file mode 100644
index 0000000..67e0de7
--- /dev/null
+++ b/src/Graylog/Gelf.hs
@@ -0,0 +1,76 @@
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE OverloadedStrings #-}
4
5module Graylog.Gelf where
6
7import Data.Aeson (ToJSON (..), Value (..), genericToJSON,
8 toJSON)
9import Data.Aeson.Casing
10import Data.Scientific
11import Data.Text (Text)
12import Data.Time
13import Data.Typeable
14import Data.Vector
15import GHC.Generics
16
17data GELF
18 = GELF
19 { _gelfVersion :: Version
20 , _gelfHost :: Text
21 , _gelfShortMessage :: Text
22 , _gelfFullMessage :: Maybe Text
23 , _gelfTimestamp :: Maybe UTCTime
24 , _gelfLevel :: Maybe SyslogLevel
25 , _gelfLine :: Maybe Word
26 , _gelfFile :: Maybe Text
27 , _gelfAdditionalFields :: Vector Field
28 }
29 deriving (Show, Typeable, Generic)
30
31instance ToJSON GELF where
32 toJSON = genericToJSON $ aesonPrefix snakeCase
33
34--
35
36data Version
37 = Version1x1
38 deriving (Eq, Show, Typeable, Generic)
39
40instance ToJSON Version where
41 toJSON Version1x1 = String "1.1"
42
43--
44
45data SyslogLevel
46 = Emergency
47 | Alert
48 | Critical
49 | Error
50 | Warning
51 | Notice
52 | Informational
53 | Debug
54 deriving (Eq, Ord, Show, Typeable, Generic)
55
56instance ToJSON SyslogLevel where
57 toJSON Emergency = Number 0
58 toJSON Alert = Number 1
59 toJSON Critical = Number 2
60 toJSON Error = Number 3
61 toJSON Warning = Number 4
62 toJSON Notice = Number 5
63 toJSON Informational = Number 6
64 toJSON Debug = Number 7
65
66--
67
68data Field
69 = FieldString Text
70 | FieldNumber Scientific
71 deriving (Eq, Show, Typeable, Generic)
72
73instance ToJSON Field where
74 toJSON (FieldString s) = String s
75 toJSON (FieldNumber n) = Number n
76