on dde14d3 help sign in
.gitignore−1
since splitsnapshots
unifiedsplit
@@ -7,4 +7,3 @@ TAGS
7*.hi
7*.hi
8*.dyn_o
8*.dyn_o
9*.dyn_hi
9*.dyn_hi
10−stack.yaml.lock
.travis.yml+9−8
@@ -9,19 +9,21 @@ addons:
9 apt:
9 apt:
10 packages:
10 packages:
11 - libgmp-dev
11 - libgmp-dev
12+ - oracle-java8-installer
12
13
13# The different configurations we want to test. You could also do things like
14# The different configurations we want to test. You could also do things like
14# change flags or use --stack-yaml to point to a different file.
15# change flags or use --stack-yaml to point to a different file.
15matrix:
16matrix:
16 include:
17 include:
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"
18+ - env: ARGS="--resolver=lts-10" ESVERSION=1.5.2 ESURL=https://download.elastic.co/elasticsearch/elasticsearch ESTESTARGS="--es-version 1"
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"
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"
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
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"
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
21− # nightlies may fail usually due to lagging dependencies
23+ # nightlies may fail from time to time
22 allow_failures:
24 allow_failures:
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"
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
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"
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
25
27
26before_install:
28before_install:
27# Download and unpack the stack executable
29# Download and unpack the stack executable
@@ -34,7 +36,6 @@ install:
34 - tar xzf elasticsearch-$ESVERSION.tar.gz
36 - tar xzf elasticsearch-$ESVERSION.tar.gz
35 # set up a repo for snapshot testing. Required in ES >= 1.6
37 # set up a repo for snapshot testing. Required in ES >= 1.6
36 - echo "path.repo = [\"/tmp\"]" >> ./elasticsearch-$ESVERSION/elasticsearch.yml
38 - echo "path.repo = [\"/tmp\"]" >> ./elasticsearch-$ESVERSION/elasticsearch.yml
37− - java -version
38 - ./elasticsearch-$ESVERSION/bin/elasticsearch &
39 - ./elasticsearch-$ESVERSION/bin/elasticsearch &
39 # Bloodhound seems to take a while to build and can sometimes stall out the build when travis detects no output.
40 # Bloodhound seems to take a while to build and can sometimes stall out the build when travis detects no output.
40
41
katip-datadog/changelog.md−4
@@ -1,7 +1,3 @@
1−0.2.0.0
2−==========
3−* Remove import of deprecated Network module
4−
50.1.0.0
10.1.0.0
6==========
2==========
7* Initial release
3* Initial release
katip-datadog/katip-datadog.cabal+1−1
@@ -1,5 +1,5 @@
1name: katip-datadog
1name: katip-datadog
2−version: 0.2.0.0
2+version: 0.1.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
36import qualified Network.Connection as C
37import 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.Bloodhound.Types
18+import Database.V1.Bloodhound.Types
19import Numeric
19import Numeric
20-------------------------------------------------------------------------------
20-------------------------------------------------------------------------------
21import Katip.Scribes.ElasticSearch
21import Katip.Scribes.ElasticSearch
22−import Katip.Scribes.ElasticSearch.Internal (ESV5)
22+import Katip.Scribes.ElasticSearch.Internal (ESV1)
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 ESV5))
37+ bench "mkDocId (randomIO)" $ nfIO (mkDocId (Proxy :: Proxy ESV1))
38 , bench "mkDocId' (shared )" $ nfIO mkDocId'
38 , bench "mkDocId' (shared )" $ nfIO mkDocId'
39 ]
39 ]
40
40
katip-elasticsearch/changelog.md−10
@@ -1,13 +1,3 @@
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−
110.6.0.0
10.6.0.0
12=======
2=======
13* Update to katip-0.8.0.0 `PermitFunc` convention. To update, for
3* Update to katip-0.8.0.0 `PermitFunc` convention. To update, for
katip-elasticsearch/docker-compose.ymldeleted−10
@@ -1,10 +0,0 @@
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.Bloodhound
9+import Database.V5.Bloodhound
10import Network.HTTP.Client
10import Network.HTTP.Client
11-------------------------------------------------------------------------------
11-------------------------------------------------------------------------------
12import Katip
12import Katip
katip-elasticsearch/katip-elasticsearch.cabal+4−1
@@ -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.7.0.0
4+version: 0.6.0.0
5license: BSD3
5license: BSD3
6license-file: LICENSE
6license-file: LICENSE
7author: Ozgun Ataman, Michael Xavier
7author: Ozgun Ataman, Michael Xavier
@@ -108,4 +108,7 @@ test-suite test
108 , bytestring
108 , bytestring
109 , tagged
109 , tagged
110
110
111+ if flag(lib-Werror)
112+ ghc-options: -Wall -Werror
113+
111 ghc-options: -threaded -rtsopts
114 ghc-options: -threaded -rtsopts
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs−5
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
2-- | Includes a scribe that can be used to log structured, JSON log
1-- | Includes a scribe that can be used to log structured, JSON log
3-- messages to ElasticSearch. These logs can be explored easily using
2-- messages to ElasticSearch. These logs can be explored easily using
4-- <https://www.elastic.co/products/kibana kibana> or your tool of
3-- <https://www.elastic.co/products/kibana kibana> or your tool of
@@ -68,16 +67,12 @@ module Katip.Scribes.ElasticSearch
68 , essIndexSettings
67 , essIndexSettings
69 , essIndexSharding
68 , essIndexSharding
70 , defaultEsScribeCfg
69 , defaultEsScribeCfg
71−#if !MIN_VERSION_bloodhound(0,17,0)
72 , defaultEsScribeCfgV1
70 , defaultEsScribeCfgV1
73−#endif
74 , defaultEsScribeCfgV5
71 , defaultEsScribeCfgV5
75 -- ** Version-Proxied APIS
72 -- ** Version-Proxied APIS
76 -- $versionproxies
73 -- $versionproxies
77 , defaultEsScribeCfg'
74 , defaultEsScribeCfg'
78−#if !MIN_VERSION_bloodhound(0,17,0)
79 , ESV1
75 , ESV1
80−#endif
81 , ESV5
76 , ESV5
82 -- * Utilities
77 -- * Utilities
83 , mkDocId
78 , mkDocId
katip-elasticsearch/src/Katip/Scribes/ElasticSearch/Internal.hs+7−18
@@ -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 as Monoid
31+import Data.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,12 +37,8 @@ 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
43import qualified Database.V1.Bloodhound as V1
40import qualified Database.V1.Bloodhound as V1
44import qualified Database.V5.Bloodhound as V5
41import qualified Database.V5.Bloodhound as V5
45−#endif
46import Network.HTTP.Client
42import Network.HTTP.Client
47import Network.HTTP.Types.Status
43import Network.HTTP.Types.Status
48import Text.Printf (printf)
44import Text.Printf (printf)
@@ -99,7 +95,7 @@ data EsScribeCfg v = EsScribeCfg {
99-- * DailyIndexSharding
95-- * DailyIndexSharding
100defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
96defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
101defaultEsScribeCfg' prx = EsScribeCfg {
97defaultEsScribeCfg' prx = EsScribeCfg {
102− essRetryPolicy = exponentialBackoff 25000 Monoid.<> limitRetries 5
98+ essRetryPolicy = exponentialBackoff 25000 <> limitRetries 5
103 , essQueueSize = EsQueueSize 1000
99 , essQueueSize = EsQueueSize 1000
104 , essPoolSize = EsPoolSize 2
100 , essPoolSize = EsPoolSize 2
105 , essAnnotateTypes = False
101 , essAnnotateTypes = False
@@ -108,22 +104,19 @@ defaultEsScribeCfg' prx = EsScribeCfg {
108 }
104 }
109
105
110
106
111−
112−
113-------------------------------------------------------------------------------
107-------------------------------------------------------------------------------
114−-- | Alias of 'defaultEsScribeCfgV5' to minimize API
108+-- | Alias of 'defaultEsScribeCfgV1' to minimize API
115-- breakage. Previous versions of katip-elasticsearch only supported
109-- breakage. Previous versions of katip-elasticsearch only supported
116−-- ES version 1 and defaulted to it.
110+-- ES version 1.
117−defaultEsScribeCfg :: EsScribeCfg ESV5
111+defaultEsScribeCfg :: EsScribeCfg ESV1
118−defaultEsScribeCfg = defaultEsScribeCfgV5
112+defaultEsScribeCfg = defaultEsScribeCfgV1
119
113
120
114
121-------------------------------------------------------------------------------
115-------------------------------------------------------------------------------
122−#if !MIN_VERSION_bloodhound(0,17,0)
123-- | EsScribeCfg that will use ElasticSearch V1
116-- | EsScribeCfg that will use ElasticSearch V1
124defaultEsScribeCfgV1 :: EsScribeCfg ESV1
117defaultEsScribeCfgV1 :: EsScribeCfg ESV1
125defaultEsScribeCfgV1 = defaultEsScribeCfg' (Typeable.Proxy :: Typeable.Proxy ESV1)
118defaultEsScribeCfgV1 = defaultEsScribeCfg' (Typeable.Proxy :: Typeable.Proxy ESV1)
126−#endif
119+
127
120
128-------------------------------------------------------------------------------
121-------------------------------------------------------------------------------
129-- | EsScribeCfg that will use ElasticSearch V5
122-- | EsScribeCfg that will use ElasticSearch V5
@@ -491,10 +484,7 @@ class ESVersion v where
491
484
492
485
493
486
494−#if !MIN_VERSION_bloodhound(0,17,0)
495data ESV1 = ESV1
487data ESV1 = ESV1
496−{-# DEPRECATED ESV1 "ESV1 is deprecated and removed in bloodhound >= 0.17.0" #-}
497−
498
488
499instance ESVersion ESV1 where
489instance ESVersion ESV1 where
500 type BHEnv ESV1 = V1.BHEnv
490 type BHEnv ESV1 = V1.BHEnv
@@ -534,7 +524,6 @@ instance ESVersion ESV1 where
534 [ "type" .= String "string"
524 [ "type" .= String "string"
535 , "index" .= String "analyzed"
525 , "index" .= String "analyzed"
536 ]
526 ]
537−#endif
538
527
539
528
540data ESV5 = ESV5
529data ESV5 = ESV5
katip-elasticsearch/test/Main.hs+7−23
@@ -34,12 +34,8 @@ 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
40import qualified Database.V1.Bloodhound as V1
37import qualified Database.V1.Bloodhound as V1
41import qualified Database.V5.Bloodhound as V5
38import qualified Database.V5.Bloodhound as V5
42−#endif
43import Network.HTTP.Client
39import Network.HTTP.Client
44import Network.HTTP.Types.Status
40import Network.HTTP.Types.Status
45import Test.QuickCheck.Instances ()
41import Test.QuickCheck.Instances ()
@@ -58,10 +54,8 @@ main :: IO ()
58main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-elasticsearch"
54main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-elasticsearch"
59 [
55 [
60 case vers of
56 case vers of
61−#if !MIN_VERSION_bloodhound(0,17,0)
62− TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
57+ TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
63−#endif
64− TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
58+ TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
65 , typeAnnotatedTests
59 , typeAnnotatedTests
66 , roundToSundayTests
60 , roundToSundayTests
67 ]
61 ]
@@ -70,26 +64,18 @@ main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-e
70
64
71
65
72-------------------------------------------------------------------------------
66-------------------------------------------------------------------------------
73−data TestWithESVersion = TestV5
67+data TestWithESVersion = TestV1
74−#if !MIN_VERSION_bloodhound(0,17,0)
68+ | TestV5
75− | TestV1
76−#endif
77− deriving (Typeable)
69+ deriving (Typeable)
78
70
79
71
80instance IsOption TestWithESVersion where
72instance IsOption TestWithESVersion where
81− defaultValue = TestV5
73+ defaultValue = TestV1
82−#if !MIN_VERSION_bloodhound(0,17,0)
83 parseValue "1" = Just TestV1
74 parseValue "1" = Just TestV1
84−#endif
85 parseValue "5" = Just TestV5
75 parseValue "5" = Just TestV5
86 parseValue _ = Nothing
76 parseValue _ = Nothing
87 optionName = Tagged "es-version"
77 optionName = Tagged "es-version"
88−#if MIN_VERSION_bloodhound(0,17,0)
89− optionHelp = Tagged "Version of ES to test against, either 1 or 5, defaulting to 5."
78+ optionHelp = Tagged "Version of ES to test against, either 1 or 5, defaulting to 1."
90−#else
91− optionHelp = Tagged "Version of ES to test against, only v5 is supported, but should work for higher versions."
92−#endif
93
79
94
80
95class ESVersion v => TestESVersion v where
81class ESVersion v => TestESVersion v where
@@ -115,7 +101,6 @@ class ESVersion v => TestESVersion v where
115 searchByIndex :: proxy v -> IndexName v -> Search v -> BH v IO (Response ByteString)
101 searchByIndex :: proxy v -> IndexName v -> Search v -> BH v IO (Response ByteString)
116
102
117
103
118−#if !MIN_VERSION_bloodhound(0,17,0)
119instance TestESVersion ESV1 where
104instance TestESVersion ESV1 where
120 type Server ESV1 = V1.Server
105 type Server ESV1 = V1.Server
121 toServer _ = V1.Server
106 toServer _ = V1.Server
@@ -137,7 +122,6 @@ instance TestESVersion ESV1 where
137 refreshIndex _ = V1.refreshIndex
122 refreshIndex _ = V1.refreshIndex
138 withBH _ = V1.withBH
123 withBH _ = V1.withBH
139 searchByIndex _ = V1.searchByIndex
124 searchByIndex _ = V1.searchByIndex
140−#endif
141
125
142
126
143instance TestESVersion ESV5 where
127instance 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 Integration:* Katip was designed to be easily integrated
19+* *Easy to 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,16 +1,3 @@
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−
140.8.2.0
10.8.2.0
15=======
2=======
16* Add `MonadFail` instances for `base` >= 4.9.0.0 [Koray Al](https://github.com/korayal)
3* 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.5.0
2+version: 0.8.2.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.9
90+ build-depends: Win32 >=2.3 && <2.6
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−1
@@ -161,7 +161,6 @@ module Katip
161 , logT
161 , logT
162 , logLoc
162 , logLoc
163 , logItem
163 , logItem
164− , logKatipItem
165 , logException
164 , logException
166 -- ** 'KatipContext': Logging With Context
165 -- ** 'KatipContext': Logging With Context
167 -- $katipcontextlogging
166 -- $katipcontextlogging
@@ -182,6 +181,7 @@ module Katip
182 , mkHandleScribe
181 , mkHandleScribe
183 , mkHandleScribeWithFormatter
182 , mkHandleScribeWithFormatter
184 , mkFileScribe
183 , mkFileScribe
184+ , mkFileScribeWithFormatter
185 , ColorStrategy (..)
185 , ColorStrategy (..)
186 , ItemFormatter
186 , ItemFormatter
187 , bracketFormat
187 , bracketFormat
katip/src/Katip/Core.hs+19−36
@@ -44,8 +44,7 @@ import Control.Monad.Trans.Either
44import Control.Monad.Trans.Except
44import Control.Monad.Trans.Except
45import Control.Monad.Trans.Maybe
45import Control.Monad.Trans.Maybe
46import Control.Monad.Trans.Reader
46import Control.Monad.Trans.Reader
47−import Control.Monad.Trans.Resource (MonadResource, ResourceT,
47+import Control.Monad.Trans.Resource (ResourceT, transResourceT)
48− transResourceT)
49import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
48import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
50import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
49import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
51import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
50import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
@@ -665,7 +664,7 @@ makeLenses ''LogEnv
665
664
666
665
667-------------------------------------------------------------------------------
666-------------------------------------------------------------------------------
668−-- | Create a reasonable default InitLogEnv. Uses an 'AutoUpdate' which
667+-- | Create a reasonable default InitLogEnv. Uses an 'AutoUdate' which
669-- updates the timer every 1ms. If you need even more timestamp
668-- updates the timer every 1ms. If you need even more timestamp
670-- precision at the cost of performance, consider setting
669-- precision at the cost of performance, consider setting
671-- '_logEnvTimer' with 'getCurrentTime'.
670-- '_logEnvTimer' with 'getCurrentTime'.
@@ -880,8 +879,7 @@ instance (Katip m) => Katip (ResourceT m) where
880-- opposed to implementing 'Katip' for your monad.
879-- opposed to implementing 'Katip' for your monad.
881newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
880newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
882 deriving ( Functor, Applicative, Monad, MonadIO
881 deriving ( Functor, Applicative, Monad, MonadIO
883− , MonadMask, MonadCatch, MonadThrow, MonadResource, MonadTrans
882+ , MonadMask, MonadCatch, MonadThrow, MonadTrans, MonadBase b)
884− , MonadBase b)
885
883
886
884
887instance MonadIO m => Katip (KatipT m) where
885instance MonadIO m => Katip (KatipT m) where
@@ -903,14 +901,9 @@ instance (MonadBaseControl b m) => MonadBaseControl b (KatipT m) where
903 restoreM = defaultRestoreM
901 restoreM = defaultRestoreM
904
902
905instance MonadUnliftIO m => MonadUnliftIO (KatipT m) where
903instance 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
910 askUnliftIO = KatipT $
904 askUnliftIO = KatipT $
911− withUnliftIO $ \u ->
905+ withUnliftIO $ \u ->
912− pure (UnliftIO (unliftIO u . unKatipT))
906+ pure (UnliftIO (unliftIO u . unKatipT))
913−#endif
914
907
915#if MIN_VERSION_base(4, 9, 0)
908#if MIN_VERSION_base(4, 9, 0)
916instance MF.MonadFail m => MF.MonadFail (KatipT m) where
909instance MF.MonadFail m => MF.MonadFail (KatipT m) where
@@ -948,29 +941,19 @@ logItem
948 -> m ()
941 -> m ()
949logItem a ns loc sev msg = do
942logItem a ns loc sev msg = do
950 LogEnv{..} <- getLogEnv
943 LogEnv{..} <- getLogEnv
951− logKatipItem =<< liftIO
944+ liftIO $ do
945+ item <- Item
952− (Item <$> pure _logEnvApp
946+ <$> pure _logEnvApp
953− <*> pure _logEnvEnv
947+ <*> pure _logEnvEnv
954− <*> pure sev
948+ <*> pure sev
955− <*> (mkThreadIdText <$> myThreadId)
949+ <*> (mkThreadIdText <$> myThreadId)
956− <*> pure _logEnvHost
950+ <*> pure _logEnvHost
957− <*> pure _logEnvPid
951+ <*> pure _logEnvPid
958− <*> pure a
952+ <*> pure a
959− <*> pure msg
953+ <*> pure msg
960− <*> _logEnvTimer
954+ <*> _logEnvTimer
961− <*> pure (_logEnvApp <> ns)
955+ <*> pure (_logEnvApp <> ns)
962− <*> pure loc)
956+ <*> 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 $
974 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
957 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
975 whenM (scribePermitItem shScribe item) $
958 whenM (scribePermitItem shScribe item) $
976 void $ atomically (tryWriteTBQueue shChan (NewItem item))
959 void $ atomically (tryWriteTBQueue shChan (NewItem item))
@@ -1019,7 +1002,7 @@ logException
1019logException a ns sev action = action `catchAny` \e -> f e >> throwM e
1002logException a ns sev action = action `catchAny` \e -> f e >> throwM e
1020 where
1003 where
1021 f e = logF a ns sev (msg e)
1004 f e = logF a ns sev (msg e)
1022− msg e = ls (T.pack "An exception has occurred: ") <> showLS e
1005+ msg e = ls (T.pack "An exception has occured: ") <> showLS e
1023
1006
1024
1007
1025-------------------------------------------------------------------------------
1008-------------------------------------------------------------------------------
katip/src/Katip/Monadic.hs+6−20
@@ -58,8 +58,7 @@ 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 (MonadResource,
61+import Control.Monad.Trans.Resource (ResourceT, transResourceT)
62− ResourceT, transResourceT)
63import Control.Monad.Trans.RWS (RWST, mapRWST)
62import Control.Monad.Trans.RWS (RWST, mapRWST)
64import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
63import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
65import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
64import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
@@ -316,7 +315,7 @@ logExceptionM
316logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
315logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
317 where
316 where
318 f e = logFM sev (msg e)
317 f e = logFM sev (msg e)
319− msg e = ls ("An exception has occurred: " :: Text) Semi.<> showLS e
318+ msg e = ls ("An exception has occured: " :: Text) Semi.<> showLS e
320
319
321
320
322-------------------------------------------------------------------------------
321-------------------------------------------------------------------------------
@@ -350,7 +349,6 @@ newtype KatipContextT m a = KatipContextT {
350 , MonadWriter w
349 , MonadWriter w
351 , MonadError e
350 , MonadError e
352 , MonadPlus
351 , MonadPlus
353− , MonadResource
354 , Alternative
352 , Alternative
355 , MonadFix
353 , MonadFix
356 , MonadTrans
354 , MonadTrans
@@ -397,15 +395,9 @@ instance (MonadIO m) => KatipContext (KatipContextT m) where
397 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
395 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
398
396
399instance MonadUnliftIO m => MonadUnliftIO (KatipContextT m) where
397instance 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
404 askUnliftIO = KatipContextT $
398 askUnliftIO = KatipContextT $
405− withUnliftIO $ \u ->
399+ withUnliftIO $ \u ->
406− pure (UnliftIO (unliftIO u . unKatipContextT))
400+ pure (UnliftIO (unliftIO u . unKatipContextT))
407−#endif
408−
409
401
410#if MIN_VERSION_base(4, 9, 0)
402#if MIN_VERSION_base(4, 9, 0)
411instance MF.MonadFail m => MF.MonadFail (KatipContextT m) where
403instance MF.MonadFail m => MF.MonadFail (KatipContextT m) where
@@ -490,15 +482,9 @@ instance MonadBaseControl b m => MonadBaseControl b (NoLoggingT m) where
490 restoreM = NoLoggingT . restoreM
482 restoreM = NoLoggingT . restoreM
491
483
492instance MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) where
484instance 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
497 askUnliftIO = NoLoggingT $
485 askUnliftIO = NoLoggingT $
498− withUnliftIO $ \u ->
486+ withUnliftIO $ \u ->
499− pure (UnliftIO (unliftIO u . runNoLoggingT))
487+ pure (UnliftIO (unliftIO u . runNoLoggingT))
500−#endif
501−
502
488
503instance MonadIO m => Katip (NoLoggingT m) where
489instance MonadIO m => Katip (NoLoggingT m) where
504 getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
490 getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
katip/src/Katip/Scribes/Handle.hs+42−26
@@ -3,17 +3,19 @@ module Katip.Scribes.Handle where
3-------------------------------------------------------------------------------
3-------------------------------------------------------------------------------
4import Control.Applicative as A
4import Control.Applicative as A
5import Control.Concurrent
5import Control.Concurrent
6−import Control.Exception (bracket_, finally)
6+import Control.Exception (finally)
7import Data.Aeson
7import Data.Aeson
8−import Data.Text.Lazy (toStrict)
8+import Data.Aeson.Text
9−import Data.Text.Lazy.Encoding (decodeUtf8)
9+import Data.ByteString.Builder as B
10−import qualified Data.HashMap.Strict as HM
10+import Data.ByteString.Lazy as BL (hPutStr)
11import Data.Monoid as M
11import Data.Monoid as M
12import Data.Scientific as S
12import Data.Scientific as S
13import Data.Text (Text)
13import Data.Text (Text)
14−import Data.Text.Lazy.Builder
14+import Data.Text.Lazy.Builder as TL
15−import Data.Text.Lazy.IO as T
15+import Data.Text.Lazy.Encoding (encodeUtf8)
16import System.IO
16import System.IO
17+import qualified Data.HashMap.Strict as HM
18+
17-------------------------------------------------------------------------------
19-------------------------------------------------------------------------------
18import Katip.Core
20import Katip.Core
19import Katip.Format.Time (formatAsLogTime)
21import Katip.Format.Time (formatAsLogTime)
@@ -21,15 +23,20 @@ import Katip.Format.Time (formatAsLogTime)
21
23
22
24
23-------------------------------------------------------------------------------
25-------------------------------------------------------------------------------
24−brackets :: Builder -> Builder
26+brackets :: TL.Builder -> TL.Builder
25brackets m = fromText "[" M.<> m <> fromText "]"
27brackets m = fromText "[" M.<> m <> fromText "]"
26
28
29+textBuilderToBS :: TL.Builder -> B.Builder
30+textBuilderToBS = B.lazyByteString . encodeUtf8 . toLazyText
31+
32+appendNL :: TL.Builder -> TL.Builder
33+appendNL b = b <> TL.singleton '\n'
27
34
28-------------------------------------------------------------------------------
35-------------------------------------------------------------------------------
29−getKeys :: LogItem s => Verbosity -> s -> [Builder]
36+getKeys :: LogItem s => Verbosity -> s -> [TL.Builder]
30getKeys verb a = concat (renderPair A.<$> HM.toList (payloadObject verb a))
37getKeys verb a = concat (renderPair A.<$> HM.toList (payloadObject verb a))
31 where
38 where
32− renderPair :: (Text, Value) -> [Builder]
39+ renderPair :: (Text, Value) -> [TL.Builder]
33 renderPair (k,v) =
40 renderPair (k,v) =
34 case v of
41 case v of
35 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
42 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
@@ -65,6 +72,19 @@ data ColorStrategy
65mkHandleScribe :: ColorStrategy -> Handle -> PermitFunc -> Verbosity -> IO Scribe
72mkHandleScribe :: ColorStrategy -> Handle -> PermitFunc -> Verbosity -> IO Scribe
66mkHandleScribe = mkHandleScribeWithFormatter bracketFormat
73mkHandleScribe = mkHandleScribeWithFormatter bracketFormat
67
74
75+
76+mkFileScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
77+ -> ColorStrategy
78+ -> FilePath
79+ -> PermitFunc
80+ -> Verbosity
81+ -> IO Scribe
82+mkFileScribeWithFormatter formatter color f permitF verb = do
83+ h <- openBinaryFile f AppendMode
84+ Scribe logger finalizer permit <- mkHandleScribeWithFormatter formatter color h permitF verb
85+ return (Scribe logger (finalizer `finally` hClose h) permit)
86+
87+
68-- | Logs to a file handle such as stdout, stderr, or a file. Takes a custom
88-- | Logs to a file handle such as stdout, stderr, or a file. Takes a custom
69-- `ItemFormatter` that can be used to format `Item` as needed.
89-- `ItemFormatter` that can be used to format `Item` as needed.
70--
90--
@@ -77,14 +97,12 @@ mkHandleScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
77 -> Verbosity
97 -> Verbosity
78 -> IO Scribe
98 -> IO Scribe
79mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
99mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
80− hSetBuffering h LineBuffering
81 colorize <- case cs of
100 colorize <- case cs of
82 ColorIfTerminal -> hIsTerminalDevice h
101 ColorIfTerminal -> hIsTerminalDevice h
83 ColorLog b -> return b
102 ColorLog b -> return b
84 lock <- newMVar ()
103 lock <- newMVar ()
85− let logger i@Item{..} = do
104+ let logger i@Item{..} = withMVar lock $ \() -> do
86− bracket_ (takeMVar lock) (putMVar lock ()) $
87− T.hPutStrLn h $ toLazyText $ itemFormatter colorize verb i
105+ BL.hPutStr h $ toLazyByteString $ itemFormatter colorize verb i
88 return $ Scribe logger (hFlush h) permitF
106 return $ Scribe logger (hFlush h) permitF
89
107
90
108
@@ -95,19 +113,17 @@ mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
95-- 'closeScribe'/'closeScribes'. Does not do log coloring. Sets handle
113-- 'closeScribe'/'closeScribes'. Does not do log coloring. Sets handle
96-- to 'LineBuffering' mode.
114-- to 'LineBuffering' mode.
97mkFileScribe :: FilePath -> PermitFunc -> Verbosity -> IO Scribe
115mkFileScribe :: FilePath -> PermitFunc -> Verbosity -> IO Scribe
98−mkFileScribe f permitF verb = do
116+mkFileScribe = mkFileScribeWithFormatter bracketFormat (ColorLog False)
99− h <- openFile f AppendMode
100− Scribe logger finalizer permit <- mkHandleScribe (ColorLog False) h permitF verb
101− return (Scribe logger (finalizer `finally` hClose h) permit)
102
117
103
118
104-------------------------------------------------------------------------------
119-------------------------------------------------------------------------------
105-- | A custom ItemFormatter for logging `Item`s. Takes a `Bool` indicating
120-- | A custom ItemFormatter for logging `Item`s. Takes a `Bool` indicating
106-- whether to colorize the output, `Verbosity` of output, and an `Item` to
121-- whether to colorize the output, `Verbosity` of output, and an `Item` to
107−-- format.
122+-- format. Note that formatter is responsible for appending the newline at the
123+-- end of the string if required
108--
124--
109-- See `bracketFormat` and `jsonFormat` for examples.
125-- See `bracketFormat` and `jsonFormat` for examples.
110−type ItemFormatter a = Bool -> Verbosity -> Item a -> Builder
126+type ItemFormatter a = Bool -> Verbosity -> Item a -> B.Builder
111
127
112
128
113formatItem :: LogItem a => ItemFormatter a
129formatItem :: LogItem a => ItemFormatter a
@@ -121,10 +137,10 @@ formatItem = bracketFormat
121-- > [2016-05-11 21:01:15][MyApp.confrabulation][Debug][myhost.example.com][PID 1724][ThreadId 1154][confrab_factor:42.0][main:Helpers.Logging Helpers/Logging.hs:41:9] Confrabulating widgets, with extra namespace and context
137-- > [2016-05-11 21:01:15][MyApp.confrabulation][Debug][myhost.example.com][PID 1724][ThreadId 1154][confrab_factor:42.0][main:Helpers.Logging Helpers/Logging.hs:41:9] Confrabulating widgets, with extra namespace and context
122-- > [2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:43:7] Namespace and context are back to normal
138-- > [2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:43:7] Namespace and context are back to normal
123bracketFormat :: LogItem a => ItemFormatter a
139bracketFormat :: LogItem a => ItemFormatter a
124−bracketFormat withColor verb Item{..} =
140+bracketFormat withColor verb Item{..} = textBuilderToBS $ appendNL $
125 brackets nowStr <>
141 brackets nowStr <>
126 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
142 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
127− brackets (fromText (renderSeverity' _itemSeverity)) <>
143+ brackets (renderSeverity' _itemSeverity) <>
128 brackets (fromString _itemHost) <>
144 brackets (fromString _itemHost) <>
129 brackets ("PID " <> fromString (show _itemProcess)) <>
145 brackets ("PID " <> fromString (show _itemProcess)) <>
130 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
146 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
@@ -135,7 +151,7 @@ bracketFormat withColor verb Item{..} =
135 nowStr = fromText (formatAsLogTime _itemTime)
151 nowStr = fromText (formatAsLogTime _itemTime)
136 ks = map brackets $ getKeys verb _itemPayload
152 ks = map brackets $ getKeys verb _itemPayload
137 renderSeverity' severity =
153 renderSeverity' severity =
138− colorBySeverity withColor severity (renderSeverity severity)
154+ colorBySeverity withColor severity (fromText $ renderSeverity severity)
139
155
140-- | Logs items as JSON. This can be useful in circumstances where you already
156-- | Logs items as JSON. This can be useful in circumstances where you already
141-- have infrastructure that is expecting JSON to be logged to a standard stream
157-- have infrastructure that is expecting JSON to be logged to a standard stream
@@ -145,15 +161,15 @@ bracketFormat withColor verb Item{..} =
145-- > {"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp","confrabulation"],"data":{"confrab_factor":42},"app":["MyApp"],"msg":"Confrabulating widgets, with extra namespace and context","pid":"10456","loc":{"loc_col":11,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":53},"host":"myhost.example.com","sev":"Debug","thread":"ThreadId 139"}
161-- > {"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp","confrabulation"],"data":{"confrab_factor":42},"app":["MyApp"],"msg":"Confrabulating widgets, with extra namespace and context","pid":"10456","loc":{"loc_col":11,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":53},"host":"myhost.example.com","sev":"Debug","thread":"ThreadId 139"}
146-- > {"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp"],"data":{},"app":["MyApp"],"msg":"Namespace and context are back to normal","pid":"10456","loc":{"loc_col":9,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":55},"host":"myhost.example.com","sev":"Info","thread":"ThreadId 139"}
162-- > {"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp"],"data":{},"app":["MyApp"],"msg":"Namespace and context are back to normal","pid":"10456","loc":{"loc_col":9,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":55},"host":"myhost.example.com","sev":"Info","thread":"ThreadId 139"}
147jsonFormat :: LogItem a => ItemFormatter a
163jsonFormat :: LogItem a => ItemFormatter a
148−jsonFormat withColor verb i =
164+jsonFormat withColor verb i = textBuilderToBS $
149− fromText $
165+ appendNL $
150 colorBySeverity withColor (_itemSeverity i) $
166 colorBySeverity withColor (_itemSeverity i) $
151− toStrict $ decodeUtf8 $ encode $ itemJson verb i
167+ encodeToTextBuilder $ itemJson verb i
152
168
153-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
169-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
154-- are colored red, `WarningS` is colored yellow, and all other messages are
170-- are colored red, `WarningS` is colored yellow, and all other messages are
155-- rendered in the default color.
171-- rendered in the default color.
156−colorBySeverity :: Bool -> Severity -> Text -> Text
172+colorBySeverity :: Bool -> Severity -> TL.Builder -> TL.Builder
157colorBySeverity withColor severity msg = case severity of
173colorBySeverity withColor severity msg = case severity of
158 EmergencyS -> red msg
174 EmergencyS -> red msg
159 AlertS -> red msg
175 AlertS -> red msg
katip/test/Katip/Tests/Scribes/Handle.hs+6−8
@@ -1,5 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE RankNTypes #-}
2+{-# LANGUAGE RankNTypes #-}
3module Katip.Tests.Scribes.Handle
3module Katip.Tests.Scribes.Handle
4 ( tests
4 ( tests
5 ) where
5 ) where
@@ -7,12 +7,11 @@ module Katip.Tests.Scribes.Handle
7-------------------------------------------------------------------------------
7-------------------------------------------------------------------------------
8import Control.Monad
8import Control.Monad
9import Data.Aeson
9import Data.Aeson
10−import qualified Data.ByteString.Char8 as B
10+import Data.ByteString.Builder as B
11import qualified Data.ByteString.Lazy as BL
11import qualified Data.ByteString.Lazy as BL
12import Data.Monoid as M
12import Data.Monoid as M
13import Data.Text (Text)
13import Data.Text (Text)
14import qualified Data.Text as T
14import qualified Data.Text as T
15−import qualified Data.Text.Encoding as T
16import qualified Data.Text.Lazy as LT
15import qualified Data.Text.Lazy as LT
17import qualified Data.Text.Lazy.Builder as LT
16import qualified Data.Text.Lazy.Builder as LT
18import Data.Time
17import Data.Time
@@ -245,14 +244,13 @@ writeJsonLog = writeFormattedLog jsonFormat
245
244
246writeFormattedLog :: (forall a . LogItem a => ItemFormatter a) -> (FilePath, Handle) -> IO (BL.ByteString)
245writeFormattedLog :: (forall a . LogItem a => ItemFormatter a) -> (FilePath, Handle) -> IO (BL.ByteString)
247writeFormattedLog format (path, h) = do
246writeFormattedLog format (path, h) = do
248− mapM_ (put . formatOne) genItems
247+ mapM_ put genItems
249− mapM_ (put . formatOne) genTypedItems
248+ mapM_ put genTypedItems
250 hClose h
249 hClose h
251 BL.readFile path
250 BL.readFile path
252 where
251 where
253− formatOne :: LogItem a => Item a -> Text
252+ put :: (LogItem a) => Item a -> IO ()
254− formatOne = LT.toStrict . LT.toLazyText . format False V3
253+ put = BL.hPutStr h . toLazyByteString . format False V3
255− put = B.hPutStrLn h . T.encodeUtf8
256
254
257setupTempFile :: IO (FilePath, Handle)
255setupTempFile :: IO (FilePath, Handle)
258setupTempFile = do
256setupTempFile = do
stack.yaml+6−5
@@ -1,14 +1,15 @@
1+nix:
2+ packages:
3+ - zlib
1−resolver: lts-16.18
4+resolver: lts-12.26
2packages:
5packages:
3 - katip
6 - katip
4 - katip-elasticsearch
7 - katip-elasticsearch
5 - katip-datadog
8 - katip-datadog
6 - katip-logzio
9 - katip-logzio
7extra-deps:
10extra-deps:
8− # ghc 8.8 support
9− - github: wireapp/bloodhound
11+ - bloodhound-0.16.0.0
10− commit: b409f52b518f20a4c20651b5893c31b7b85cb9b1
12+ - unliftio-core-0.1.2.0
11−allow-newer: true
12flags:
13flags:
13 katip:
14 katip:
14 lib-Werror: true
15 lib-Werror: true