on master help sign in
.gitignore+1
since splitsnapshots
unifiedsplit
@@ -7,3 +7,4 @@ TAGS
7*.hi
7*.hi
8*.dyn_o
8*.dyn_o
9*.dyn_hi
9*.dyn_hi
10+stack.yaml.lock
.travis.yml+8−9
@@ -9,21 +9,19 @@ addons:
9 apt:
9 apt:
10 packages:
10 packages:
11 - libgmp-dev
11 - libgmp-dev
12− - oracle-java8-installer
13
12
14# The different configurations we want to test. You could also do things like
13# The different configurations we want to test. You could also do things like
15# change flags or use --stack-yaml to point to a different file.
14# change flags or use --stack-yaml to point to a different file.
16matrix:
15matrix:
17 include:
16 include:
18− - env: ARGS="--resolver=lts-10" ESVERSION=1.5.2 ESURL=https://download.elastic.co/elasticsearch/elasticsearch ESTESTARGS="--es-version 1"
17+ - env: ARGS="--resolver=lts-16" ESVERSION=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
19− - env: ARGS="--resolver=lts-11" ESVERSION=1.5.2 ESURL=https://download.elastic.co/elasticsearch/elasticsearch ESTESTARGS="--es-version 1"
18+ - env: ARGS="--resolver=lts-16" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
20− - env: ARGS="--resolver=lts-12" ESVERSION=1.5.2 ESURL=https://download.elastic.co/elasticsearch/elasticsearch ESTESTARGS="--es-version 1"
21− - env: ARGS="--resolver=nightly" ESVERSION=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m" JAVA_HOME=/usr/lib/jvm/java-8-oracle
19+ - env: ARGS="--resolver=nightly" ESVERSION=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
22− - env: ARGS="--resolver=nightly" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m" JAVA_HOME=/usr/lib/jvm/java-8-oracle
20+ - env: ARGS="--resolver=nightly" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
23− # nightlies may fail from time to time
21+ # nightlies may fail usually due to lagging dependencies
24 allow_failures:
22 allow_failures:
25− - env: ARGS="--resolver=nightly" ESVERSION=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m" JAVA_HOME=/usr/lib/jvm/java-8-oracle
23+ - env: ARGS="--resolver=nightly" ESVERSION=5.5.0 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
26− - env: ARGS="--resolver=nightly" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m" JAVA_HOME=/usr/lib/jvm/java-8-oracle
24+ - env: ARGS="--resolver=nightly" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
27
25
28before_install:
26before_install:
29# Download and unpack the stack executable
27# Download and unpack the stack executable
@@ -36,6 +34,7 @@ install:
36 - tar xzf elasticsearch-$ESVERSION.tar.gz
34 - tar xzf elasticsearch-$ESVERSION.tar.gz
37 # set up a repo for snapshot testing. Required in ES >= 1.6
35 # set up a repo for snapshot testing. Required in ES >= 1.6
38 - echo "path.repo = [\"/tmp\"]" >> ./elasticsearch-$ESVERSION/elasticsearch.yml
36 - echo "path.repo = [\"/tmp\"]" >> ./elasticsearch-$ESVERSION/elasticsearch.yml
37+ - java -version
39 - ./elasticsearch-$ESVERSION/bin/elasticsearch &
38 - ./elasticsearch-$ESVERSION/bin/elasticsearch &
40 # Bloodhound seems to take a while to build and can sometimes stall out the build when travis detects no output.
39 # Bloodhound seems to take a while to build and can sometimes stall out the build when travis detects no output.
41
40
katip-datadog/changelog.md+4
@@ -1,3 +1,7 @@
1+0.2.0.0
2+==========
3+* Remove import of deprecated Network module
4+
10.1.0.0
50.1.0.0
2==========
6==========
3* Initial release
7* Initial release
katip-datadog/katip-datadog.cabal+1−1
@@ -1,5 +1,5 @@
1name: katip-datadog
1name: katip-datadog
2−version: 0.1.0.0
2+version: 0.2.0.0
3synopsis: Datadog scribe for the Katip logging framework
3synopsis: Datadog scribe for the Katip logging framework
4description: See README.md for more details.
4description: See README.md for more details.
5license: BSD3
5license: BSD3
katip-datadog/src/Katip/Scribes/Datadog/TCP.hs+1−1
@@ -33,8 +33,8 @@ import qualified Data.Text.Lazy.Builder as B
33import Data.Time (NominalDiffTime)
33import Data.Time (NominalDiffTime)
34import Katip
34import Katip
35import Katip.Core (LocJs (..))
35import Katip.Core (LocJs (..))
36−import qualified Network as Net
37import qualified Network.Connection as C
36import qualified Network.Connection as C
37+import qualified Network.Socket as Net
38import qualified System.Posix.Types as POSIX
38import qualified System.Posix.Types as POSIX
39-------------------------------------------------------------------------------
39-------------------------------------------------------------------------------
40
40
katip-elasticsearch/bench/Main.hs+3−3
@@ -15,11 +15,11 @@ import qualified Data.HashMap.Strict as HM
15import Data.Proxy (Proxy (..))
15import Data.Proxy (Proxy (..))
16import System.Random
16import System.Random
17import qualified Data.Text as T
17import qualified Data.Text as T
18−import Database.V1.Bloodhound.Types
18+import Database.Bloodhound.Types
19import Numeric
19import Numeric
20-------------------------------------------------------------------------------
20-------------------------------------------------------------------------------
21import Katip.Scribes.ElasticSearch
21import Katip.Scribes.ElasticSearch
22−import Katip.Scribes.ElasticSearch.Internal (ESV1)
22+import Katip.Scribes.ElasticSearch.Internal (ESV5)
23-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
24
24
25main :: IO ()
25main :: IO ()
@@ -34,7 +34,7 @@ main = do
34mkDocIdBenchmark :: Benchmark
34mkDocIdBenchmark :: Benchmark
35mkDocIdBenchmark = bgroup "mkDocId"
35mkDocIdBenchmark = bgroup "mkDocId"
36 [
36 [
37− bench "mkDocId (randomIO)" $ nfIO (mkDocId (Proxy :: Proxy ESV1))
37+ bench "mkDocId (randomIO)" $ nfIO (mkDocId (Proxy :: Proxy ESV5))
38 , bench "mkDocId' (shared )" $ nfIO mkDocId'
38 , bench "mkDocId' (shared )" $ nfIO mkDocId'
39 ]
39 ]
40
40
katip-elasticsearch/changelog.md+10
@@ -1,3 +1,13 @@
1+0.7.0.0
2+=======
3+* Make compatible with unreleased bloodhound 0.17
4+* Deprecate use of ES version 1 which has been removed from bloodhound
5+ 0.17. All users should move over to ESV5 which should work for
6+ versions 5 and up.
7+* Default configuration to ESV5
8+* Add deprecation warnings for ESV1. Support for ESV1 will be removed
9+ in the future.
10+
10.6.0.0
110.6.0.0
2=======
12=======
3* Update to katip-0.8.0.0 `PermitFunc` convention. To update, for
13* Update to katip-0.8.0.0 `PermitFunc` convention. To update, for
katip-elasticsearch/docker-compose.ymlnew file+10
@@ -0,0 +1,10 @@
1+version: "3.7"
2+services:
3+ # https://hub.docker.com/_/elasticsearch
4+ elasticsearch:
5+ image: elasticsearch:5-alpine
6+ ports:
7+ - target: 9200
8+ published: 9200
9+ protocol: tcp
10+ mode: host
katip-elasticsearch/examples/example.hs+1−1
@@ -6,7 +6,7 @@ module Main
6
6
7-------------------------------------------------------------------------------
7-------------------------------------------------------------------------------
8import Control.Exception
8import Control.Exception
9−import Database.V5.Bloodhound
9+import Database.Bloodhound
10import Network.HTTP.Client
10import Network.HTTP.Client
11-------------------------------------------------------------------------------
11-------------------------------------------------------------------------------
12import Katip
12import Katip
katip-elasticsearch/katip-elasticsearch.cabal+1−4
@@ -1,7 +1,7 @@
1name: katip-elasticsearch
1name: katip-elasticsearch
2synopsis: ElasticSearch scribe for the Katip logging framework.
2synopsis: ElasticSearch scribe for the Katip logging framework.
3description: See README.md for more details.
3description: See README.md for more details.
4−version: 0.6.0.0
4+version: 0.7.0.0
5license: BSD3
5license: BSD3
6license-file: LICENSE
6license-file: LICENSE
7author: Ozgun Ataman, Michael Xavier
7author: Ozgun Ataman, Michael Xavier
@@ -108,7 +108,4 @@ test-suite test
108 , bytestring
108 , bytestring
109 , tagged
109 , tagged
110
110
111− if flag(lib-Werror)
112− ghc-options: -Wall -Werror
113−
114 ghc-options: -threaded -rtsopts
111 ghc-options: -threaded -rtsopts
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- | Includes a scribe that can be used to log structured, JSON log
2-- | Includes a scribe that can be used to log structured, JSON log
2-- messages to ElasticSearch. These logs can be explored easily using
3-- messages to ElasticSearch. These logs can be explored easily using
3-- <https://www.elastic.co/products/kibana kibana> or your tool of
4-- <https://www.elastic.co/products/kibana kibana> or your tool of
@@ -67,12 +68,16 @@ module Katip.Scribes.ElasticSearch
67 , essIndexSettings
68 , essIndexSettings
68 , essIndexSharding
69 , essIndexSharding
69 , defaultEsScribeCfg
70 , defaultEsScribeCfg
71+#if !MIN_VERSION_bloodhound(0,17,0)
70 , defaultEsScribeCfgV1
72 , defaultEsScribeCfgV1
73+#endif
71 , defaultEsScribeCfgV5
74 , defaultEsScribeCfgV5
72 -- ** Version-Proxied APIS
75 -- ** Version-Proxied APIS
73 -- $versionproxies
76 -- $versionproxies
74 , defaultEsScribeCfg'
77 , defaultEsScribeCfg'
78+#if !MIN_VERSION_bloodhound(0,17,0)
75 , ESV1
79 , ESV1
80+#endif
76 , ESV5
81 , ESV5
77 -- * Utilities
82 -- * Utilities
78 , mkDocId
83 , mkDocId
katip-elasticsearch/src/Katip/Scribes/ElasticSearch/Internal.hs+18−7
@@ -28,7 +28,7 @@ import Control.Retry (RetryPolicy,
28import Data.Aeson
28import Data.Aeson
29import Data.ByteString.Lazy (ByteString)
29import Data.ByteString.Lazy (ByteString)
30import Data.List.NonEmpty (NonEmpty (..))
30import Data.List.NonEmpty (NonEmpty (..))
31−import Data.Monoid ((<>))
31+import Data.Monoid as Monoid
32import Data.Text (Text)
32import Data.Text (Text)
33import qualified Data.Text as T
33import qualified Data.Text as T
34import qualified Data.Text.Encoding as T
34import qualified Data.Text.Encoding as T
@@ -37,8 +37,12 @@ import Data.Time.Calendar.WeekDate
37import Data.Typeable as Typeable
37import Data.Typeable as Typeable
38import Data.UUID
38import Data.UUID
39import qualified Data.UUID.V4 as UUID4
39import qualified Data.UUID.V4 as UUID4
40+#if MIN_VERSION_bloodhound(0,17,0)
41+import qualified Database.Bloodhound as V5
42+#else
40import qualified Database.V1.Bloodhound as V1
43import qualified Database.V1.Bloodhound as V1
41import qualified Database.V5.Bloodhound as V5
44import qualified Database.V5.Bloodhound as V5
45+#endif
42import Network.HTTP.Client
46import Network.HTTP.Client
43import Network.HTTP.Types.Status
47import Network.HTTP.Types.Status
44import Text.Printf (printf)
48import Text.Printf (printf)
@@ -95,7 +99,7 @@ data EsScribeCfg v = EsScribeCfg {
95-- * DailyIndexSharding
99-- * DailyIndexSharding
96defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
100defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
97defaultEsScribeCfg' prx = EsScribeCfg {
101defaultEsScribeCfg' prx = EsScribeCfg {
98− essRetryPolicy = exponentialBackoff 25000 <> limitRetries 5
102+ essRetryPolicy = exponentialBackoff 25000 Monoid.<> limitRetries 5
99 , essQueueSize = EsQueueSize 1000
103 , essQueueSize = EsQueueSize 1000
100 , essPoolSize = EsPoolSize 2
104 , essPoolSize = EsPoolSize 2
101 , essAnnotateTypes = False
105 , essAnnotateTypes = False
@@ -104,19 +108,22 @@ defaultEsScribeCfg' prx = EsScribeCfg {
104 }
108 }
105
109
106
110
111+
112+
107-------------------------------------------------------------------------------
113-------------------------------------------------------------------------------
108−-- | Alias of 'defaultEsScribeCfgV1' to minimize API
114+-- | Alias of 'defaultEsScribeCfgV5' to minimize API
109-- breakage. Previous versions of katip-elasticsearch only supported
115-- breakage. Previous versions of katip-elasticsearch only supported
110−-- ES version 1.
116+-- ES version 1 and defaulted to it.
111−defaultEsScribeCfg :: EsScribeCfg ESV1
117+defaultEsScribeCfg :: EsScribeCfg ESV5
112−defaultEsScribeCfg = defaultEsScribeCfgV1
118+defaultEsScribeCfg = defaultEsScribeCfgV5
113
119
114
120
115-------------------------------------------------------------------------------
121-------------------------------------------------------------------------------
122+#if !MIN_VERSION_bloodhound(0,17,0)
116-- | EsScribeCfg that will use ElasticSearch V1
123-- | EsScribeCfg that will use ElasticSearch V1
117defaultEsScribeCfgV1 :: EsScribeCfg ESV1
124defaultEsScribeCfgV1 :: EsScribeCfg ESV1
118defaultEsScribeCfgV1 = defaultEsScribeCfg' (Typeable.Proxy :: Typeable.Proxy ESV1)
125defaultEsScribeCfgV1 = defaultEsScribeCfg' (Typeable.Proxy :: Typeable.Proxy ESV1)
119−
126+#endif
120
127
121-------------------------------------------------------------------------------
128-------------------------------------------------------------------------------
122-- | EsScribeCfg that will use ElasticSearch V5
129-- | EsScribeCfg that will use ElasticSearch V5
@@ -484,7 +491,10 @@ class ESVersion v where
484
491
485
492
486
493
494+#if !MIN_VERSION_bloodhound(0,17,0)
487data ESV1 = ESV1
495data ESV1 = ESV1
496+{-# DEPRECATED ESV1 "ESV1 is deprecated and removed in bloodhound >= 0.17.0" #-}
497+
488
498
489instance ESVersion ESV1 where
499instance ESVersion ESV1 where
490 type BHEnv ESV1 = V1.BHEnv
500 type BHEnv ESV1 = V1.BHEnv
@@ -524,6 +534,7 @@ instance ESVersion ESV1 where
524 [ "type" .= String "string"
534 [ "type" .= String "string"
525 , "index" .= String "analyzed"
535 , "index" .= String "analyzed"
526 ]
536 ]
537+#endif
527
538
528
539
529data ESV5 = ESV5
540data ESV5 = ESV5
katip-elasticsearch/test/Main.hs+23−7
@@ -34,8 +34,12 @@ import Data.Time
34import Data.Time.Calendar.WeekDate
34import Data.Time.Calendar.WeekDate
35import Data.Typeable as Typeable
35import Data.Typeable as Typeable
36import qualified Data.Vector as V
36import qualified Data.Vector as V
37+#if MIN_VERSION_bloodhound(0,17,0)
38+import qualified Database.Bloodhound as V5
39+#else
37import qualified Database.V1.Bloodhound as V1
40import qualified Database.V1.Bloodhound as V1
38import qualified Database.V5.Bloodhound as V5
41import qualified Database.V5.Bloodhound as V5
42+#endif
39import Network.HTTP.Client
43import Network.HTTP.Client
40import Network.HTTP.Types.Status
44import Network.HTTP.Types.Status
41import Test.QuickCheck.Instances ()
45import Test.QuickCheck.Instances ()
@@ -54,8 +58,10 @@ main :: IO ()
54main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-elasticsearch"
58main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-elasticsearch"
55 [
59 [
56 case vers of
60 case vers of
61+#if !MIN_VERSION_bloodhound(0,17,0)
57− TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
62+ TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
63+#endif
58− TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
64+ TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
59 , typeAnnotatedTests
65 , typeAnnotatedTests
60 , roundToSundayTests
66 , roundToSundayTests
61 ]
67 ]
@@ -64,18 +70,26 @@ main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-e
64
70
65
71
66-------------------------------------------------------------------------------
72-------------------------------------------------------------------------------
67−data TestWithESVersion = TestV1
73+data TestWithESVersion = TestV5
68− | TestV5
74+#if !MIN_VERSION_bloodhound(0,17,0)
75+ | TestV1
76+#endif
69− deriving (Typeable)
77+ deriving (Typeable)
70
78
71
79
72instance IsOption TestWithESVersion where
80instance IsOption TestWithESVersion where
73− defaultValue = TestV1
81+ defaultValue = TestV5
82+#if !MIN_VERSION_bloodhound(0,17,0)
74 parseValue "1" = Just TestV1
83 parseValue "1" = Just TestV1
84+#endif
75 parseValue "5" = Just TestV5
85 parseValue "5" = Just TestV5
76 parseValue _ = Nothing
86 parseValue _ = Nothing
77 optionName = Tagged "es-version"
87 optionName = Tagged "es-version"
88+#if MIN_VERSION_bloodhound(0,17,0)
78− optionHelp = Tagged "Version of ES to test against, either 1 or 5, defaulting to 1."
89+ optionHelp = Tagged "Version of ES to test against, either 1 or 5, defaulting to 5."
90+#else
91+ optionHelp = Tagged "Version of ES to test against, only v5 is supported, but should work for higher versions."
92+#endif
79
93
80
94
81class ESVersion v => TestESVersion v where
95class ESVersion v => TestESVersion v where
@@ -101,6 +115,7 @@ class ESVersion v => TestESVersion v where
101 searchByIndex :: proxy v -> IndexName v -> Search v -> BH v IO (Response ByteString)
115 searchByIndex :: proxy v -> IndexName v -> Search v -> BH v IO (Response ByteString)
102
116
103
117
118+#if !MIN_VERSION_bloodhound(0,17,0)
104instance TestESVersion ESV1 where
119instance TestESVersion ESV1 where
105 type Server ESV1 = V1.Server
120 type Server ESV1 = V1.Server
106 toServer _ = V1.Server
121 toServer _ = V1.Server
@@ -122,6 +137,7 @@ instance TestESVersion ESV1 where
122 refreshIndex _ = V1.refreshIndex
137 refreshIndex _ = V1.refreshIndex
123 withBH _ = V1.withBH
138 withBH _ = V1.withBH
124 searchByIndex _ = V1.searchByIndex
139 searchByIndex _ = V1.searchByIndex
140+#endif
125
141
126
142
127instance TestESVersion ESV5 where
143instance TestESVersion ESV5 where
katip/README.md+1−1
@@ -16,7 +16,7 @@ Kâtip (pronounced kah-tip) is the Turkish word for scribe.
16 add context that will be automatically merged in with existing log
16 add context that will be automatically merged in with existing log
17 context.
17 context.
18
18
19−* *Easy to Integration:* Katip was designed to be easily integrated
19+* *Easy Integration:* Katip was designed to be easily integrated
20 into existing monads. By using typeclasses for logging facilities,
20 into existing monads. By using typeclasses for logging facilities,
21 individual subsystems and even libraries can easily add their own
21 individual subsystems and even libraries can easily add their own
22 namespacing and context without having any knowledge of their
22 namespacing and context without having any knowledge of their
katip/changelog.md+13
@@ -1,3 +1,16 @@
1+0.8.5.0
2+=======
3+* Add MonadResource instances [#121](https://github.com/Soostone/katip/pull/121)
4+
5+0.8.4.0
6+=======
7+* Add support for unliftio-core 0.2 while maintaining backwards-compatible support for 0.1
8+
9+0.8.3.0
10+=======
11+
12+* Add `logKatipItem` function and reimplement `logItem` to use it. [vlatkoB](https://github.com/vlatkoB)
13+
10.8.2.0
140.8.2.0
2=======
15=======
3* Add `MonadFail` instances for `base` >= 4.9.0.0 [Koray Al](https://github.com/korayal)
16* Add `MonadFail` instances for `base` >= 4.9.0.0 [Koray Al](https://github.com/korayal)
katip/katip.cabal+2−2
@@ -1,5 +1,5 @@
1name: katip
1name: katip
2−version: 0.8.2.0
2+version: 0.8.5.0
3synopsis: A structured logging framework.
3synopsis: A structured logging framework.
4description:
4description:
5 Katip is a structured logging framework. See README.md for more details.
5 Katip is a structured logging framework. See README.md for more details.
@@ -87,7 +87,7 @@ library
87 if flag(lib-Werror)
87 if flag(lib-Werror)
88 ghc-options: -Werror
88 ghc-options: -Werror
89 if os(windows)
89 if os(windows)
90− build-depends: Win32 >=2.3 && <2.6
90+ build-depends: Win32 >=2.3 && <2.9
91 exposed-modules: Katip.Compat
91 exposed-modules: Katip.Compat
92 else
92 else
93 build-depends: unix >= 2.5 && <2.8
93 build-depends: unix >= 2.5 && <2.8
katip/src/Katip.hs+1
@@ -161,6 +161,7 @@ module Katip
161 , logT
161 , logT
162 , logLoc
162 , logLoc
163 , logItem
163 , logItem
164+ , logKatipItem
164 , logException
165 , logException
165 -- ** 'KatipContext': Logging With Context
166 -- ** 'KatipContext': Logging With Context
166 -- $katipcontextlogging
167 -- $katipcontextlogging
katip/src/Katip/Core.hs+44−32
@@ -31,7 +31,6 @@ import qualified Control.Concurrent.STM.TBQueue as BQ
31import Control.Exception.Safe
31import Control.Exception.Safe
32import Control.Monad (unless, void, when)
32import Control.Monad (unless, void, when)
33import Control.Monad.Base
33import Control.Monad.Base
34−import Data.Text.Encoding as T
35#if MIN_VERSION_base(4, 9, 0)
34#if MIN_VERSION_base(4, 9, 0)
36import qualified Control.Monad.Fail as MF
35import qualified Control.Monad.Fail as MF
37#endif
36#endif
@@ -45,7 +44,8 @@ import Control.Monad.Trans.Either
45import Control.Monad.Trans.Except
44import Control.Monad.Trans.Except
46import Control.Monad.Trans.Maybe
45import Control.Monad.Trans.Maybe
47import Control.Monad.Trans.Reader
46import Control.Monad.Trans.Reader
48−import Control.Monad.Trans.Resource (ResourceT, transResourceT)
47+import Control.Monad.Trans.Resource (MonadResource, ResourceT,
48+ transResourceT)
49import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
49import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
50import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
50import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
51import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
51import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
@@ -56,7 +56,6 @@ import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT,
56import Data.Aeson (FromJSON (..), ToJSON (..),
56import Data.Aeson (FromJSON (..), ToJSON (..),
57 object)
57 object)
58import qualified Data.Aeson as A
58import qualified Data.Aeson as A
59−import qualified Data.ByteString.Builder as B
60import Data.Foldable as FT
59import Data.Foldable as FT
61import qualified Data.HashMap.Strict as HM
60import qualified Data.HashMap.Strict as HM
62import Data.List
61import Data.List
@@ -67,6 +66,7 @@ import Data.String
67import Data.String.Conv
66import Data.String.Conv
68import Data.Text (Text)
67import Data.Text (Text)
69import qualified Data.Text as T
68import qualified Data.Text as T
69+import qualified Data.Text.Lazy.Builder as B
70import Data.Time
70import Data.Time
71import GHC.Generics hiding (to)
71import GHC.Generics hiding (to)
72#if MIN_VERSION_base(4, 8, 0)
72#if MIN_VERSION_base(4, 8, 0)
@@ -200,15 +200,13 @@ instance FromJSON Verbosity where
200 _ -> fail $ "Invalid Verbosity " ++ toS s
200 _ -> fail $ "Invalid Verbosity " ++ toS s
201
201
202
202
203−
204−
205-------------------------------------------------------------------------------
203-------------------------------------------------------------------------------
206-- | Log message with Builder underneath; use '<>' to concat in O(1).
204-- | Log message with Builder underneath; use '<>' to concat in O(1).
207newtype LogStr = LogStr { unLogStr :: B.Builder }
205newtype LogStr = LogStr { unLogStr :: B.Builder }
208− deriving (Generic)
206+ deriving (Generic, Show, Eq)
209
207
210instance IsString LogStr where
208instance IsString LogStr where
211− fromString = LogStr . logStrText . T.pack
209+ fromString = LogStr . B.fromString
212
210
213
211
214instance Semigroup LogStr where
212instance Semigroup LogStr where
@@ -220,20 +218,18 @@ instance Monoid LogStr where
220 mempty = LogStr mempty
218 mempty = LogStr mempty
221
219
222
220
223−-- instance FromJSON LogStr where
221+instance FromJSON LogStr where
224−-- parseJSON = A.withText "LogStr" parseLogStr
222+ parseJSON = A.withText "LogStr" parseLogStr
225−-- where
223+ where
226−-- parseLogStr = return . LogStr . B.fromText
224+ parseLogStr = return . LogStr . B.fromText
227
225
228-------------------------------------------------------------------------------
226-------------------------------------------------------------------------------
229-- | Pack any string-like thing into a 'LogStr'. This will
227-- | Pack any string-like thing into a 'LogStr'. This will
230-- automatically work on 'String', 'ByteString', 'Text' and any of the
228-- automatically work on 'String', 'ByteString', 'Text' and any of the
231-- lazy variants.
229-- lazy variants.
232logStr :: StringConv a Text => a -> LogStr
230logStr :: StringConv a Text => a -> LogStr
233−logStr t = logStrText . toS
231+logStr t = LogStr (B.fromText $ toS t)
234
232
235−logStrText :: Text -> LogStr
236−logStrText = LogStr . B.byteString . T.encodeUtf8
237
233
238-------------------------------------------------------------------------------
234-------------------------------------------------------------------------------
239-- | Shorthand for 'logStr'
235-- | Shorthand for 'logStr'
@@ -669,7 +665,7 @@ makeLenses ''LogEnv
669
665
670
666
671-------------------------------------------------------------------------------
667-------------------------------------------------------------------------------
672−-- | Create a reasonable default InitLogEnv. Uses an 'AutoUdate' which
668+-- | Create a reasonable default InitLogEnv. Uses an 'AutoUpdate' which
673-- updates the timer every 1ms. If you need even more timestamp
669-- updates the timer every 1ms. If you need even more timestamp
674-- precision at the cost of performance, consider setting
670-- precision at the cost of performance, consider setting
675-- '_logEnvTimer' with 'getCurrentTime'.
671-- '_logEnvTimer' with 'getCurrentTime'.
@@ -884,7 +880,8 @@ instance (Katip m) => Katip (ResourceT m) where
884-- opposed to implementing 'Katip' for your monad.
880-- opposed to implementing 'Katip' for your monad.
885newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
881newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
886 deriving ( Functor, Applicative, Monad, MonadIO
882 deriving ( Functor, Applicative, Monad, MonadIO
887− , MonadMask, MonadCatch, MonadThrow, MonadTrans, MonadBase b)
883+ , MonadMask, MonadCatch, MonadThrow, MonadResource, MonadTrans
884+ , MonadBase b)
888
885
889
886
890instance MonadIO m => Katip (KatipT m) where
887instance MonadIO m => Katip (KatipT m) where
@@ -906,9 +903,14 @@ instance (MonadBaseControl b m) => MonadBaseControl b (KatipT m) where
906 restoreM = defaultRestoreM
903 restoreM = defaultRestoreM
907
904
908instance MonadUnliftIO m => MonadUnliftIO (KatipT m) where
905instance MonadUnliftIO m => MonadUnliftIO (KatipT m) where
906+#if MIN_VERSION_unliftio_core(0, 2, 0)
907+ withRunInIO inner = KatipT $ ReaderT $ \le -> withRunInIO $ \run ->
908+ inner (run . runKatipT le)
909+#else
909 askUnliftIO = KatipT $
910 askUnliftIO = KatipT $
910− withUnliftIO $ \u ->
911+ withUnliftIO $ \u ->
911− pure (UnliftIO (unliftIO u . unKatipT))
912+ pure (UnliftIO (unliftIO u . unKatipT))
913+#endif
912
914
913#if MIN_VERSION_base(4, 9, 0)
915#if MIN_VERSION_base(4, 9, 0)
914instance MF.MonadFail m => MF.MonadFail (KatipT m) where
916instance MF.MonadFail m => MF.MonadFail (KatipT m) where
@@ -946,19 +948,29 @@ logItem
946 -> m ()
948 -> m ()
947logItem a ns loc sev msg = do
949logItem a ns loc sev msg = do
948 LogEnv{..} <- getLogEnv
950 LogEnv{..} <- getLogEnv
949− liftIO $ do
951+ logKatipItem =<< liftIO
950− item <- Item
951− <$> pure _logEnvApp
952+ (Item <$> pure _logEnvApp
952− <*> pure _logEnvEnv
953+ <*> pure _logEnvEnv
953− <*> pure sev
954+ <*> pure sev
954− <*> (mkThreadIdText <$> myThreadId)
955+ <*> (mkThreadIdText <$> myThreadId)
955− <*> pure _logEnvHost
956+ <*> pure _logEnvHost
956− <*> pure _logEnvPid
957+ <*> pure _logEnvPid
957− <*> pure a
958+ <*> pure a
958− <*> pure msg
959+ <*> pure msg
959− <*> _logEnvTimer
960+ <*> _logEnvTimer
960− <*> pure (_logEnvApp <> ns)
961+ <*> pure (_logEnvApp <> ns)
961− <*> pure loc
962+ <*> pure loc)
963+
964+-- | Log already constructed 'Item'. This is the lowest level function that other log*
965+-- functions use.
966+-- It can be useful when implementing centralised logging services.
967+logKatipItem
968+ :: (A.Applicative m, LogItem a, Katip m)
969+ => Item a
970+ -> m ()
971+logKatipItem item = do
972+ LogEnv{..} <- getLogEnv
973+ liftIO $
962 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
974 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
963 whenM (scribePermitItem shScribe item) $
975 whenM (scribePermitItem shScribe item) $
964 void $ atomically (tryWriteTBQueue shChan (NewItem item))
976 void $ atomically (tryWriteTBQueue shChan (NewItem item))
@@ -1007,7 +1019,7 @@ logException
1007logException a ns sev action = action `catchAny` \e -> f e >> throwM e
1019logException a ns sev action = action `catchAny` \e -> f e >> throwM e
1008 where
1020 where
1009 f e = logF a ns sev (msg e)
1021 f e = logF a ns sev (msg e)
1010− msg e = ls (T.pack "An exception has occured: ") <> showLS e
1022+ msg e = ls (T.pack "An exception has occurred: ") <> showLS e
1011
1023
1012
1024
1013-------------------------------------------------------------------------------
1025-------------------------------------------------------------------------------
katip/src/Katip/Monadic.hs+20−6
@@ -58,7 +58,8 @@ import Control.Monad.Trans.Either (EitherT, mapEitherT)
58import Control.Monad.Trans.Except (ExceptT, mapExceptT)
58import Control.Monad.Trans.Except (ExceptT, mapExceptT)
59import Control.Monad.Trans.Identity (IdentityT, mapIdentityT)
59import Control.Monad.Trans.Identity (IdentityT, mapIdentityT)
60import Control.Monad.Trans.Maybe (MaybeT, mapMaybeT)
60import Control.Monad.Trans.Maybe (MaybeT, mapMaybeT)
61−import Control.Monad.Trans.Resource (ResourceT, transResourceT)
61+import Control.Monad.Trans.Resource (MonadResource,
62+ ResourceT, transResourceT)
62import Control.Monad.Trans.RWS (RWST, mapRWST)
63import Control.Monad.Trans.RWS (RWST, mapRWST)
63import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
64import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
64import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
65import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
@@ -315,7 +316,7 @@ logExceptionM
315logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
316logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
316 where
317 where
317 f e = logFM sev (msg e)
318 f e = logFM sev (msg e)
318− msg e = ls ("An exception has occured: " :: Text) Semi.<> showLS e
319+ msg e = ls ("An exception has occurred: " :: Text) Semi.<> showLS e
319
320
320
321
321-------------------------------------------------------------------------------
322-------------------------------------------------------------------------------
@@ -349,6 +350,7 @@ newtype KatipContextT m a = KatipContextT {
349 , MonadWriter w
350 , MonadWriter w
350 , MonadError e
351 , MonadError e
351 , MonadPlus
352 , MonadPlus
353+ , MonadResource
352 , Alternative
354 , Alternative
353 , MonadFix
355 , MonadFix
354 , MonadTrans
356 , MonadTrans
@@ -395,9 +397,15 @@ instance (MonadIO m) => KatipContext (KatipContextT m) where
395 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
397 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
396
398
397instance MonadUnliftIO m => MonadUnliftIO (KatipContextT m) where
399instance MonadUnliftIO m => MonadUnliftIO (KatipContextT m) where
400+#if MIN_VERSION_unliftio_core(0, 2, 0)
401+ withRunInIO inner = KatipContextT $ ReaderT $ \lts -> withRunInIO $ \run ->
402+ inner (run . runKatipContextT (ltsLogEnv lts) (ltsContext lts) (ltsNamespace lts))
403+#else
398 askUnliftIO = KatipContextT $
404 askUnliftIO = KatipContextT $
399− withUnliftIO $ \u ->
405+ withUnliftIO $ \u ->
400− pure (UnliftIO (unliftIO u . unKatipContextT))
406+ pure (UnliftIO (unliftIO u . unKatipContextT))
407+#endif
408+
401
409
402#if MIN_VERSION_base(4, 9, 0)
410#if MIN_VERSION_base(4, 9, 0)
403instance MF.MonadFail m => MF.MonadFail (KatipContextT m) where
411instance MF.MonadFail m => MF.MonadFail (KatipContextT m) where
@@ -482,9 +490,15 @@ instance MonadBaseControl b m => MonadBaseControl b (NoLoggingT m) where
482 restoreM = NoLoggingT . restoreM
490 restoreM = NoLoggingT . restoreM
483
491
484instance MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) where
492instance MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) where
493+#if MIN_VERSION_unliftio_core(0, 2, 0)
494+ withRunInIO inner = NoLoggingT $ withRunInIO $ \run ->
495+ inner (run . runNoLoggingT)
496+#else
485 askUnliftIO = NoLoggingT $
497 askUnliftIO = NoLoggingT $
486− withUnliftIO $ \u ->
498+ withUnliftIO $ \u ->
487− pure (UnliftIO (unliftIO u . runNoLoggingT))
499+ pure (UnliftIO (unliftIO u . runNoLoggingT))
500+#endif
501+
488
502
489instance MonadIO m => Katip (NoLoggingT m) where
503instance MonadIO m => Katip (NoLoggingT m) where
490 getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
504 getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
katip/src/Katip/Scribes/Handle.hs+20−23
@@ -4,17 +4,15 @@ module Katip.Scribes.Handle where
4import Control.Applicative as A
4import Control.Applicative as A
5import Control.Concurrent
5import Control.Concurrent
6import Control.Exception (bracket_, finally)
6import Control.Exception (bracket_, finally)
7−import Data.ByteString.Lazy as BL (hPutStr)
8−import Data.ByteString.Builder as B
9import Data.Aeson
7import Data.Aeson
10−import Data.Text as T (pack)
8+import Data.Text.Lazy (toStrict)
11−import Data.Text.Encoding as T
12−import Data.Text.Lazy as TL (toStrict)
13−import Data.Text.Lazy.Encoding as TL (decodeUtf8)
9+import Data.Text.Lazy.Encoding (decodeUtf8)
14import qualified Data.HashMap.Strict as HM
10import qualified Data.HashMap.Strict as HM
15import Data.Monoid as M
11import Data.Monoid as M
16import Data.Scientific as S
12import Data.Scientific as S
17import Data.Text (Text)
13import Data.Text (Text)
14+import Data.Text.Lazy.Builder
15+import Data.Text.Lazy.IO as T
18import System.IO
16import System.IO
19-------------------------------------------------------------------------------
17-------------------------------------------------------------------------------
20import Katip.Core
18import Katip.Core
@@ -22,26 +20,23 @@ import Katip.Format.Time (formatAsLogTime)
22-------------------------------------------------------------------------------
20-------------------------------------------------------------------------------
23
21
24
22
25−
26−fromText :: Text -> Builder
27−fromText = B.byteString . T.encodeUtf8
28−
29-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
30brackets :: Builder -> Builder
24brackets :: Builder -> Builder
31−brackets m = fromText "[" <> m <> fromText "]"
25+brackets m = fromText "[" M.<> m <> fromText "]"
26+
32
27
33-------------------------------------------------------------------------------
28-------------------------------------------------------------------------------
34getKeys :: LogItem s => Verbosity -> s -> [Builder]
29getKeys :: LogItem s => Verbosity -> s -> [Builder]
35−getKeys verb a = HM.toList (payloadObject verb a) >>= renderPair
30+getKeys verb a = concat (renderPair A.<$> HM.toList (payloadObject verb a))
36 where
31 where
37 renderPair :: (Text, Value) -> [Builder]
32 renderPair :: (Text, Value) -> [Builder]
38 renderPair (k,v) =
33 renderPair (k,v) =
39 case v of
34 case v of
40 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
35 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
41− String t -> [fromText k <> string7 ":" <> fromText t]
36+ String t -> [fromText (k <> ":" <> t)]
42− Number n -> [fromText k <> string7 ":" <> string7 (formatNumber n)]
37+ Number n -> [fromText (k <> ":") <> fromString (formatNumber n)]
43− Bool b -> [fromText k <> string7 ":" <> string7 (show b)]
38+ Bool b -> [fromText (k <> ":") <> fromString (show b)]
44− Null -> [fromText k <> string7 ":null"]
39+ Null -> [fromText (k <> ":null")]
45 _ -> mempty -- Can't think of a sensible way to handle arrays
40 _ -> mempty -- Can't think of a sensible way to handle arrays
46 formatNumber :: Scientific -> String
41 formatNumber :: Scientific -> String
47 formatNumber n =
42 formatNumber n =
@@ -82,12 +77,14 @@ mkHandleScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
82 -> Verbosity
77 -> Verbosity
83 -> IO Scribe
78 -> IO Scribe
84mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
79mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
80+ hSetBuffering h LineBuffering
85 colorize <- case cs of
81 colorize <- case cs of
86 ColorIfTerminal -> hIsTerminalDevice h
82 ColorIfTerminal -> hIsTerminalDevice h
87 ColorLog b -> return b
83 ColorLog b -> return b
88 lock <- newMVar ()
84 lock <- newMVar ()
89− let logger i@Item{..} = withMVar lock $ \() -> do
85+ let logger i@Item{..} = do
86+ bracket_ (takeMVar lock) (putMVar lock ()) $
90− BL.hPutStr h $ toLazyByteString $ itemFormatter colorize verb i
87+ T.hPutStrLn h $ toLazyText $ itemFormatter colorize verb i
91 return $ Scribe logger (hFlush h) permitF
88 return $ Scribe logger (hFlush h) permitF
92
89
93
90
@@ -110,7 +107,7 @@ mkFileScribe f permitF verb = do
110-- format.
107-- format.
111--
108--
112-- See `bracketFormat` and `jsonFormat` for examples.
109-- See `bracketFormat` and `jsonFormat` for examples.
113−type ItemFormatter a = Bool -> Verbosity -> Item a -> B.Builder
110+type ItemFormatter a = Bool -> Verbosity -> Item a -> Builder
114
111
115
112
116formatItem :: LogItem a => ItemFormatter a
113formatItem :: LogItem a => ItemFormatter a
@@ -128,11 +125,11 @@ bracketFormat withColor verb Item{..} =
128 brackets nowStr <>
125 brackets nowStr <>
129 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
126 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
130 brackets (fromText (renderSeverity' _itemSeverity)) <>
127 brackets (fromText (renderSeverity' _itemSeverity)) <>
131− brackets (fromText (T.pack _itemHost)) <>
128+ brackets (fromString _itemHost) <>
132− brackets ("PID " <> fromText (T.pack $ show _itemProcess)) <>
129+ brackets ("PID " <> fromString (show _itemProcess)) <>
133 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
130 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
134 mconcat ks <>
131 mconcat ks <>
135− maybe mempty (brackets . fromText . T.pack . locationToString) _itemLoc <>
132+ maybe mempty (brackets . fromString . locationToString) _itemLoc <>
136 fromText " " <> (unLogStr _itemMessage)
133 fromText " " <> (unLogStr _itemMessage)
137 where
134 where
138 nowStr = fromText (formatAsLogTime _itemTime)
135 nowStr = fromText (formatAsLogTime _itemTime)
@@ -151,7 +148,7 @@ jsonFormat :: LogItem a => ItemFormatter a
151jsonFormat withColor verb i =
148jsonFormat withColor verb i =
152 fromText $
149 fromText $
153 colorBySeverity withColor (_itemSeverity i) $
150 colorBySeverity withColor (_itemSeverity i) $
154− toStrict $ TL.decodeUtf8 $ encode $ itemJson verb i
151+ toStrict $ decodeUtf8 $ encode $ itemJson verb i
155
152
156-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
153-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
157-- are colored red, `WarningS` is colored yellow, and all other messages are
154-- are colored red, `WarningS` is colored yellow, and all other messages are
stack.yaml+5−3
@@ -1,12 +1,14 @@
1−resolver: lts-12.26
1+resolver: lts-16.18
2packages:
2packages:
3 - katip
3 - katip
4 - katip-elasticsearch
4 - katip-elasticsearch
5 - katip-datadog
5 - katip-datadog
6 - katip-logzio
6 - katip-logzio
7extra-deps:
7extra-deps:
8+ # ghc 8.8 support
8− - bloodhound-0.16.0.0
9+ - github: wireapp/bloodhound
9− - unliftio-core-0.1.2.0
10+ commit: b409f52b518f20a4c20651b5893c31b7b85cb9b1
11+allow-newer: true
10flags:
12flags:
11 katip:
13 katip:
12 lib-Werror: true
14 lib-Werror: true