on 1194bb8 help sign in
21 files changed+100−192
since splitsnapshots
unifiedsplit
.gitignore−1 .travis.yml+9−8 katip-datadog/changelog.md−4 katip-datadog/katip-datadog.cabal+1−1 katip-datadog/src/Katip/Scribes/Datadog/TCP.hs+1−1 katip-elasticsearch/bench/Main.hs+3−3 katip-elasticsearch/changelog.md−10 katip-elasticsearch/docker-compose.yml−10 katip-elasticsearch/examples/example.hs+1−1 katip-elasticsearch/katip-elasticsearch.cabal+4−1 katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs−5 katip-elasticsearch/src/Katip/Scribes/ElasticSearch/Internal.hs+7−18 katip-elasticsearch/test/Main.hs+7−23 katip/README.md+1−1 katip/changelog.md−13 katip/katip.cabal+2−2 katip/src/Katip.hs−1 katip/src/Katip/Core.hs+32−44 katip/src/Katip/Monadic.hs+6−20 katip/src/Katip/Scribes/Handle.hs+23−20 stack.yaml+3−5
.gitignore−1
@@ -7,4 +7,3 @@ TAGS
77*.hi
88*.dyn_o
99*.dyn_hi
10−stack.yaml.lock
.travis.yml+9−8
@@ -9,19 +9,21 @@ addons:
99 apt:
1010 packages:
1111 - libgmp-dev
12+ - oracle-java8-installer
1213
1314# The different configurations we want to test. You could also do things like
1415# change flags or use --stack-yaml to point to a different file.
1516matrix:
1617 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-16" ESVERSION=6.2.2 ESURL=https://artifacts.elastic.co/downloads/elasticsearch ESTESTARGS="--es-version 5" ES_JAVA_OPTS="-Xms500m -Xmx750m"
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"
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"
21− # nightlies may fail usually due to lagging dependencies
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"
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
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
23+ # nightlies may fail from time to time
2224 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"
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"
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
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
2527
2628before_install:
2729# Download and unpack the stack executable
@@ -34,7 +36,6 @@ install:
3436 - tar xzf elasticsearch-$ESVERSION.tar.gz
3537 # set up a repo for snapshot testing. Required in ES >= 1.6
3638 - echo "path.repo = [\"/tmp\"]" >> ./elasticsearch-$ESVERSION/elasticsearch.yml
37− - java -version
3839 - ./elasticsearch-$ESVERSION/bin/elasticsearch &
3940 # Bloodhound seems to take a while to build and can sometimes stall out the build when travis detects no output.
4041
katip-datadog/changelog.md−4
@@ -1,7 +1,3 @@
1−0.2.0.0
2−==========
3−* Remove import of deprecated Network module
4−
510.1.0.0
62==========
73* Initial release
katip-datadog/katip-datadog.cabal+1−1
@@ -1,5 +1,5 @@
11name: katip-datadog
2−version: 0.2.0.0
2+version: 0.1.0.0
33synopsis: Datadog scribe for the Katip logging framework
44description: See README.md for more details.
55license: BSD3
katip-datadog/src/Katip/Scribes/Datadog/TCP.hs+1−1
@@ -33,8 +33,8 @@ import qualified Data.Text.Lazy.Builder as B
3333import Data.Time (NominalDiffTime)
3434import Katip
3535import Katip.Core (LocJs (..))
36+import qualified Network as Net
3637import qualified Network.Connection as C
37−import qualified Network.Socket as Net
3838import qualified System.Posix.Types as POSIX
3939-------------------------------------------------------------------------------
4040
katip-elasticsearch/bench/Main.hs+3−3
@@ -15,11 +15,11 @@ import qualified Data.HashMap.Strict as HM
1515import Data.Proxy (Proxy (..))
1616import System.Random
1717import qualified Data.Text as T
18−import Database.Bloodhound.Types
18+import Database.V1.Bloodhound.Types
1919import Numeric
2020-------------------------------------------------------------------------------
2121import Katip.Scribes.ElasticSearch
22−import Katip.Scribes.ElasticSearch.Internal (ESV5)
22+import Katip.Scribes.ElasticSearch.Internal (ESV1)
2323-------------------------------------------------------------------------------
2424
2525main :: IO ()
@@ -34,7 +34,7 @@ main = do
3434mkDocIdBenchmark :: Benchmark
3535mkDocIdBenchmark = bgroup "mkDocId"
3636 [
37− bench "mkDocId (randomIO)" $ nfIO (mkDocId (Proxy :: Proxy ESV5))
37+ bench "mkDocId (randomIO)" $ nfIO (mkDocId (Proxy :: Proxy ESV1))
3838 , bench "mkDocId' (shared )" $ nfIO mkDocId'
3939 ]
4040
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−
1110.6.0.0
122=======
133* 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
66
77-------------------------------------------------------------------------------
88import Control.Exception
9−import Database.Bloodhound
9+import Database.V5.Bloodhound
1010import Network.HTTP.Client
1111-------------------------------------------------------------------------------
1212import Katip
katip-elasticsearch/katip-elasticsearch.cabal+4−1
@@ -1,7 +1,7 @@
11name: katip-elasticsearch
22synopsis: ElasticSearch scribe for the Katip logging framework.
33description: See README.md for more details.
4−version: 0.7.0.0
4+version: 0.6.0.0
55license: BSD3
66license-file: LICENSE
77author: Ozgun Ataman, Michael Xavier
@@ -108,4 +108,7 @@ test-suite test
108108 , bytestring
109109 , tagged
110110
111+ if flag(lib-Werror)
112+ ghc-options: -Wall -Werror
113+
111114 ghc-options: -threaded -rtsopts
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs−5
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
21-- | Includes a scribe that can be used to log structured, JSON log
32-- messages to ElasticSearch. These logs can be explored easily using
43-- <https://www.elastic.co/products/kibana kibana> or your tool of
@@ -68,16 +67,12 @@ module Katip.Scribes.ElasticSearch
6867 , essIndexSettings
6968 , essIndexSharding
7069 , defaultEsScribeCfg
71−#if !MIN_VERSION_bloodhound(0,17,0)
7270 , defaultEsScribeCfgV1
73−#endif
7471 , defaultEsScribeCfgV5
7572 -- ** Version-Proxied APIS
7673 -- $versionproxies
7774 , defaultEsScribeCfg'
78−#if !MIN_VERSION_bloodhound(0,17,0)
7975 , ESV1
80−#endif
8176 , ESV5
8277 -- * Utilities
8378 , mkDocId
katip-elasticsearch/src/Katip/Scribes/ElasticSearch/Internal.hs+7−18
@@ -28,7 +28,7 @@ import Control.Retry (RetryPolicy,
2828import Data.Aeson
2929import Data.ByteString.Lazy (ByteString)
3030import Data.List.NonEmpty (NonEmpty (..))
31−import Data.Monoid as Monoid
31+import Data.Monoid ((<>))
3232import Data.Text (Text)
3333import qualified Data.Text as T
3434import qualified Data.Text.Encoding as T
@@ -37,12 +37,8 @@ import Data.Time.Calendar.WeekDate
3737import Data.Typeable as Typeable
3838import Data.UUID
3939import qualified Data.UUID.V4 as UUID4
40−#if MIN_VERSION_bloodhound(0,17,0)
41−import qualified Database.Bloodhound as V5
42−#else
4340import qualified Database.V1.Bloodhound as V1
4441import qualified Database.V5.Bloodhound as V5
45−#endif
4642import Network.HTTP.Client
4743import Network.HTTP.Types.Status
4844import Text.Printf (printf)
@@ -99,7 +95,7 @@ data EsScribeCfg v = EsScribeCfg {
9995-- * DailyIndexSharding
10096defaultEsScribeCfg' :: ESVersion v => proxy v -> EsScribeCfg v
10197defaultEsScribeCfg' prx = EsScribeCfg {
102− essRetryPolicy = exponentialBackoff 25000 Monoid.<> limitRetries 5
98+ essRetryPolicy = exponentialBackoff 25000 <> limitRetries 5
10399 , essQueueSize = EsQueueSize 1000
104100 , essPoolSize = EsPoolSize 2
105101 , essAnnotateTypes = False
@@ -108,22 +104,19 @@ defaultEsScribeCfg' prx = EsScribeCfg {
108104 }
109105
110106
111−
112−
113107-------------------------------------------------------------------------------
114−-- | Alias of 'defaultEsScribeCfgV5' to minimize API
108+-- | Alias of 'defaultEsScribeCfgV1' to minimize API
115109-- breakage. Previous versions of katip-elasticsearch only supported
116−-- ES version 1 and defaulted to it.
117−defaultEsScribeCfg :: EsScribeCfg ESV5
118−defaultEsScribeCfg = defaultEsScribeCfgV5
110+-- ES version 1.
111+defaultEsScribeCfg :: EsScribeCfg ESV1
112+defaultEsScribeCfg = defaultEsScribeCfgV1
119113
120114
121115-------------------------------------------------------------------------------
122−#if !MIN_VERSION_bloodhound(0,17,0)
123116-- | EsScribeCfg that will use ElasticSearch V1
124117defaultEsScribeCfgV1 :: EsScribeCfg ESV1
125118defaultEsScribeCfgV1 = defaultEsScribeCfg' (Typeable.Proxy :: Typeable.Proxy ESV1)
126−#endif
119+
127120
128121-------------------------------------------------------------------------------
129122-- | EsScribeCfg that will use ElasticSearch V5
@@ -491,10 +484,7 @@ class ESVersion v where
491484
492485
493486
494−#if !MIN_VERSION_bloodhound(0,17,0)
495487data ESV1 = ESV1
496−{-# DEPRECATED ESV1 "ESV1 is deprecated and removed in bloodhound >= 0.17.0" #-}
497−
498488
499489instance ESVersion ESV1 where
500490 type BHEnv ESV1 = V1.BHEnv
@@ -534,7 +524,6 @@ instance ESVersion ESV1 where
534524 [ "type" .= String "string"
535525 , "index" .= String "analyzed"
536526 ]
537−#endif
538527
539528
540529data ESV5 = ESV5
katip-elasticsearch/test/Main.hs+7−23
@@ -34,12 +34,8 @@ import Data.Time
3434import Data.Time.Calendar.WeekDate
3535import Data.Typeable as Typeable
3636import qualified Data.Vector as V
37−#if MIN_VERSION_bloodhound(0,17,0)
38−import qualified Database.Bloodhound as V5
39−#else
4037import qualified Database.V1.Bloodhound as V1
4138import qualified Database.V5.Bloodhound as V5
42−#endif
4339import Network.HTTP.Client
4440import Network.HTTP.Types.Status
4541import Test.QuickCheck.Instances ()
@@ -58,10 +54,8 @@ main :: IO ()
5854main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-elasticsearch"
5955 [
6056 case vers of
61−#if !MIN_VERSION_bloodhound(0,17,0)
62− TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
63−#endif
64− TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
57+ TestV1 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV1)
58+ TestV5 -> esTests (Typeable.Proxy :: Typeable.Proxy ESV5)
6559 , typeAnnotatedTests
6660 , roundToSundayTests
6761 ]
@@ -70,26 +64,18 @@ main = defaultMainWithIngredients ings $ askOption $ \vers -> testGroup "katip-e
7064
7165
7266-------------------------------------------------------------------------------
73−data TestWithESVersion = TestV5
74−#if !MIN_VERSION_bloodhound(0,17,0)
75− | TestV1
76−#endif
77− deriving (Typeable)
67+data TestWithESVersion = TestV1
68+ | TestV5
69+ deriving (Typeable)
7870
7971
8072instance IsOption TestWithESVersion where
81− defaultValue = TestV5
82−#if !MIN_VERSION_bloodhound(0,17,0)
73+ defaultValue = TestV1
8374 parseValue "1" = Just TestV1
84−#endif
8575 parseValue "5" = Just TestV5
8676 parseValue _ = Nothing
8777 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."
90−#else
91− optionHelp = Tagged "Version of ES to test against, only v5 is supported, but should work for higher versions."
92−#endif
78+ optionHelp = Tagged "Version of ES to test against, either 1 or 5, defaulting to 1."
9379
9480
9581class ESVersion v => TestESVersion v where
@@ -115,7 +101,6 @@ class ESVersion v => TestESVersion v where
115101 searchByIndex :: proxy v -> IndexName v -> Search v -> BH v IO (Response ByteString)
116102
117103
118−#if !MIN_VERSION_bloodhound(0,17,0)
119104instance TestESVersion ESV1 where
120105 type Server ESV1 = V1.Server
121106 toServer _ = V1.Server
@@ -137,7 +122,6 @@ instance TestESVersion ESV1 where
137122 refreshIndex _ = V1.refreshIndex
138123 withBH _ = V1.withBH
139124 searchByIndex _ = V1.searchByIndex
140−#endif
141125
142126
143127instance TestESVersion ESV5 where
katip/README.md+1−1
@@ -16,7 +16,7 @@ Kâtip (pronounced kah-tip) is the Turkish word for scribe.
1616 add context that will be automatically merged in with existing log
1717 context.
1818
19−* *Easy Integration:* Katip was designed to be easily integrated
19+* *Easy to Integration:* Katip was designed to be easily integrated
2020 into existing monads. By using typeclasses for logging facilities,
2121 individual subsystems and even libraries can easily add their own
2222 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−
1410.8.2.0
152=======
163* Add `MonadFail` instances for `base` >= 4.9.0.0 [Koray Al](https://github.com/korayal)
katip/katip.cabal+2−2
@@ -1,5 +1,5 @@
11name: katip
2−version: 0.8.5.0
2+version: 0.8.2.0
33synopsis: A structured logging framework.
44description:
55 Katip is a structured logging framework. See README.md for more details.
@@ -87,7 +87,7 @@ library
8787 if flag(lib-Werror)
8888 ghc-options: -Werror
8989 if os(windows)
90− build-depends: Win32 >=2.3 && <2.9
90+ build-depends: Win32 >=2.3 && <2.6
9191 exposed-modules: Katip.Compat
9292 else
9393 build-depends: unix >= 2.5 && <2.8
katip/src/Katip.hs−1
@@ -161,7 +161,6 @@ module Katip
161161 , logT
162162 , logLoc
163163 , logItem
164− , logKatipItem
165164 , logException
166165 -- ** 'KatipContext': Logging With Context
167166 -- $katipcontextlogging
katip/src/Katip/Core.hs+32−44
@@ -31,6 +31,7 @@ import qualified Control.Concurrent.STM.TBQueue as BQ
3131import Control.Exception.Safe
3232import Control.Monad (unless, void, when)
3333import Control.Monad.Base
34+import Data.Text.Encoding as T
3435#if MIN_VERSION_base(4, 9, 0)
3536import qualified Control.Monad.Fail as MF
3637#endif
@@ -44,8 +45,7 @@ import Control.Monad.Trans.Either
4445import Control.Monad.Trans.Except
4546import Control.Monad.Trans.Maybe
4647import Control.Monad.Trans.Reader
47−import Control.Monad.Trans.Resource (MonadResource, ResourceT,
48− transResourceT)
48+import Control.Monad.Trans.Resource (ResourceT, transResourceT)
4949import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
5050import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
5151import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
@@ -56,6 +56,7 @@ import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT,
5656import Data.Aeson (FromJSON (..), ToJSON (..),
5757 object)
5858import qualified Data.Aeson as A
59+import qualified Data.ByteString.Builder as B
5960import Data.Foldable as FT
6061import qualified Data.HashMap.Strict as HM
6162import Data.List
@@ -66,7 +67,6 @@ import Data.String
6667import Data.String.Conv
6768import Data.Text (Text)
6869import qualified Data.Text as T
69−import qualified Data.Text.Lazy.Builder as B
7070import Data.Time
7171import GHC.Generics hiding (to)
7272#if MIN_VERSION_base(4, 8, 0)
@@ -200,13 +200,15 @@ instance FromJSON Verbosity where
200200 _ -> fail $ "Invalid Verbosity " ++ toS s
201201
202202
203+
204+
203205-------------------------------------------------------------------------------
204206-- | Log message with Builder underneath; use '<>' to concat in O(1).
205207newtype LogStr = LogStr { unLogStr :: B.Builder }
206− deriving (Generic, Show, Eq)
208+ deriving (Generic)
207209
208210instance IsString LogStr where
209− fromString = LogStr . B.fromString
211+ fromString = LogStr . logStrText . T.pack
210212
211213
212214instance Semigroup LogStr where
@@ -218,18 +220,20 @@ instance Monoid LogStr where
218220 mempty = LogStr mempty
219221
220222
221−instance FromJSON LogStr where
222− parseJSON = A.withText "LogStr" parseLogStr
223− where
224− parseLogStr = return . LogStr . B.fromText
223+-- instance FromJSON LogStr where
224+-- parseJSON = A.withText "LogStr" parseLogStr
225+-- where
226+-- parseLogStr = return . LogStr . B.fromText
225227
226228-------------------------------------------------------------------------------
227229-- | Pack any string-like thing into a 'LogStr'. This will
228230-- automatically work on 'String', 'ByteString', 'Text' and any of the
229231-- lazy variants.
230232logStr :: StringConv a Text => a -> LogStr
231−logStr t = LogStr (B.fromText $ toS t)
233+logStr t = logStrText . toS
232234
235+logStrText :: Text -> LogStr
236+logStrText = LogStr . B.byteString . T.encodeUtf8
233237
234238-------------------------------------------------------------------------------
235239-- | Shorthand for 'logStr'
@@ -665,7 +669,7 @@ makeLenses ''LogEnv
665669
666670
667671-------------------------------------------------------------------------------
668−-- | Create a reasonable default InitLogEnv. Uses an 'AutoUpdate' which
672+-- | Create a reasonable default InitLogEnv. Uses an 'AutoUdate' which
669673-- updates the timer every 1ms. If you need even more timestamp
670674-- precision at the cost of performance, consider setting
671675-- '_logEnvTimer' with 'getCurrentTime'.
@@ -880,8 +884,7 @@ instance (Katip m) => Katip (ResourceT m) where
880884-- opposed to implementing 'Katip' for your monad.
881885newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
882886 deriving ( Functor, Applicative, Monad, MonadIO
883− , MonadMask, MonadCatch, MonadThrow, MonadResource, MonadTrans
884− , MonadBase b)
887+ , MonadMask, MonadCatch, MonadThrow, MonadTrans, MonadBase b)
885888
886889
887890instance MonadIO m => Katip (KatipT m) where
@@ -903,14 +906,9 @@ instance (MonadBaseControl b m) => MonadBaseControl b (KatipT m) where
903906 restoreM = defaultRestoreM
904907
905908instance 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
910909 askUnliftIO = KatipT $
911− withUnliftIO $ \u ->
912− pure (UnliftIO (unliftIO u . unKatipT))
913−#endif
910+ withUnliftIO $ \u ->
911+ pure (UnliftIO (unliftIO u . unKatipT))
914912
915913#if MIN_VERSION_base(4, 9, 0)
916914instance MF.MonadFail m => MF.MonadFail (KatipT m) where
@@ -948,29 +946,19 @@ logItem
948946 -> m ()
949947logItem a ns loc sev msg = do
950948 LogEnv{..} <- getLogEnv
951− logKatipItem =<< liftIO
952− (Item <$> pure _logEnvApp
953− <*> pure _logEnvEnv
954− <*> pure sev
955− <*> (mkThreadIdText <$> myThreadId)
956− <*> pure _logEnvHost
957− <*> pure _logEnvPid
958− <*> pure a
959− <*> pure msg
960− <*> _logEnvTimer
961− <*> pure (_logEnvApp <> ns)
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 $
949+ liftIO $ do
950+ item <- Item
951+ <$> pure _logEnvApp
952+ <*> pure _logEnvEnv
953+ <*> pure sev
954+ <*> (mkThreadIdText <$> myThreadId)
955+ <*> pure _logEnvHost
956+ <*> pure _logEnvPid
957+ <*> pure a
958+ <*> pure msg
959+ <*> _logEnvTimer
960+ <*> pure (_logEnvApp <> ns)
961+ <*> pure loc
974962 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
975963 whenM (scribePermitItem shScribe item) $
976964 void $ atomically (tryWriteTBQueue shChan (NewItem item))
@@ -1019,7 +1007,7 @@ logException
10191007logException a ns sev action = action `catchAny` \e -> f e >> throwM e
10201008 where
10211009 f e = logF a ns sev (msg e)
1022− msg e = ls (T.pack "An exception has occurred: ") <> showLS e
1010+ msg e = ls (T.pack "An exception has occured: ") <> showLS e
10231011
10241012
10251013-------------------------------------------------------------------------------
katip/src/Katip/Monadic.hs+6−20
@@ -58,8 +58,7 @@ import Control.Monad.Trans.Either (EitherT, mapEitherT)
5858import Control.Monad.Trans.Except (ExceptT, mapExceptT)
5959import Control.Monad.Trans.Identity (IdentityT, mapIdentityT)
6060import Control.Monad.Trans.Maybe (MaybeT, mapMaybeT)
61−import Control.Monad.Trans.Resource (MonadResource,
62− ResourceT, transResourceT)
61+import Control.Monad.Trans.Resource (ResourceT, transResourceT)
6362import Control.Monad.Trans.RWS (RWST, mapRWST)
6463import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
6564import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
@@ -316,7 +315,7 @@ logExceptionM
316315logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
317316 where
318317 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
320319
321320
322321-------------------------------------------------------------------------------
@@ -350,7 +349,6 @@ newtype KatipContextT m a = KatipContextT {
350349 , MonadWriter w
351350 , MonadError e
352351 , MonadPlus
353− , MonadResource
354352 , Alternative
355353 , MonadFix
356354 , MonadTrans
@@ -397,15 +395,9 @@ instance (MonadIO m) => KatipContext (KatipContextT m) where
397395 localKatipNamespace f (KatipContextT m) = KatipContextT $ local (\s -> s { ltsNamespace = f (ltsNamespace s)}) m
398396
399397instance 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
404398 askUnliftIO = KatipContextT $
405− withUnliftIO $ \u ->
406− pure (UnliftIO (unliftIO u . unKatipContextT))
407−#endif
408−
399+ withUnliftIO $ \u ->
400+ pure (UnliftIO (unliftIO u . unKatipContextT))
409401
410402#if MIN_VERSION_base(4, 9, 0)
411403instance MF.MonadFail m => MF.MonadFail (KatipContextT m) where
@@ -490,15 +482,9 @@ instance MonadBaseControl b m => MonadBaseControl b (NoLoggingT m) where
490482 restoreM = NoLoggingT . restoreM
491483
492484instance 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
497485 askUnliftIO = NoLoggingT $
498− withUnliftIO $ \u ->
499− pure (UnliftIO (unliftIO u . runNoLoggingT))
500−#endif
501−
486+ withUnliftIO $ \u ->
487+ pure (UnliftIO (unliftIO u . runNoLoggingT))
502488
503489instance MonadIO m => Katip (NoLoggingT m) where
504490 getLogEnv = liftIO (initLogEnv "NoLoggingT" "no-logging")
katip/src/Katip/Scribes/Handle.hs+23−20
@@ -4,15 +4,17 @@ module Katip.Scribes.Handle where
44import Control.Applicative as A
55import Control.Concurrent
66import Control.Exception (bracket_, finally)
7+import Data.ByteString.Lazy as BL (hPutStr)
8+import Data.ByteString.Builder as B
79import Data.Aeson
8−import Data.Text.Lazy (toStrict)
9−import Data.Text.Lazy.Encoding (decodeUtf8)
10+import Data.Text as T (pack)
11+import Data.Text.Encoding as T
12+import Data.Text.Lazy as TL (toStrict)
13+import Data.Text.Lazy.Encoding as TL (decodeUtf8)
1014import qualified Data.HashMap.Strict as HM
1115import Data.Monoid as M
1216import Data.Scientific as S
1317import Data.Text (Text)
14−import Data.Text.Lazy.Builder
15−import Data.Text.Lazy.IO as T
1618import System.IO
1719-------------------------------------------------------------------------------
1820import Katip.Core
@@ -20,23 +22,26 @@ import Katip.Format.Time (formatAsLogTime)
2022-------------------------------------------------------------------------------
2123
2224
25+
26+fromText :: Text -> Builder
27+fromText = B.byteString . T.encodeUtf8
28+
2329-------------------------------------------------------------------------------
2430brackets :: Builder -> Builder
25−brackets m = fromText "[" M.<> m <> fromText "]"
26−
31+brackets m = fromText "[" <> m <> fromText "]"
2732
2833-------------------------------------------------------------------------------
2934getKeys :: LogItem s => Verbosity -> s -> [Builder]
30−getKeys verb a = concat (renderPair A.<$> HM.toList (payloadObject verb a))
35+getKeys verb a = HM.toList (payloadObject verb a) >>= renderPair
3136 where
3237 renderPair :: (Text, Value) -> [Builder]
3338 renderPair (k,v) =
3439 case v of
3540 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
36− String t -> [fromText (k <> ":" <> t)]
37− Number n -> [fromText (k <> ":") <> fromString (formatNumber n)]
38− Bool b -> [fromText (k <> ":") <> fromString (show b)]
39− Null -> [fromText (k <> ":null")]
41+ String t -> [fromText k <> string7 ":" <> fromText t]
42+ Number n -> [fromText k <> string7 ":" <> string7 (formatNumber n)]
43+ Bool b -> [fromText k <> string7 ":" <> string7 (show b)]
44+ Null -> [fromText k <> string7 ":null"]
4045 _ -> mempty -- Can't think of a sensible way to handle arrays
4146 formatNumber :: Scientific -> String
4247 formatNumber n =
@@ -77,14 +82,12 @@ mkHandleScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
7782 -> Verbosity
7883 -> IO Scribe
7984mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
80− hSetBuffering h LineBuffering
8185 colorize <- case cs of
8286 ColorIfTerminal -> hIsTerminalDevice h
8387 ColorLog b -> return b
8488 lock <- newMVar ()
85− let logger i@Item{..} = do
86− bracket_ (takeMVar lock) (putMVar lock ()) $
87− T.hPutStrLn h $ toLazyText $ itemFormatter colorize verb i
89+ let logger i@Item{..} = withMVar lock $ \() -> do
90+ BL.hPutStr h $ toLazyByteString $ itemFormatter colorize verb i
8891 return $ Scribe logger (hFlush h) permitF
8992
9093
@@ -107,7 +110,7 @@ mkFileScribe f permitF verb = do
107110-- format.
108111--
109112-- See `bracketFormat` and `jsonFormat` for examples.
110−type ItemFormatter a = Bool -> Verbosity -> Item a -> Builder
113+type ItemFormatter a = Bool -> Verbosity -> Item a -> B.Builder
111114
112115
113116formatItem :: LogItem a => ItemFormatter a
@@ -125,11 +128,11 @@ bracketFormat withColor verb Item{..} =
125128 brackets nowStr <>
126129 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
127130 brackets (fromText (renderSeverity' _itemSeverity)) <>
128− brackets (fromString _itemHost) <>
129− brackets ("PID " <> fromString (show _itemProcess)) <>
131+ brackets (fromText (T.pack _itemHost)) <>
132+ brackets ("PID " <> fromText (T.pack $ show _itemProcess)) <>
130133 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
131134 mconcat ks <>
132− maybe mempty (brackets . fromString . locationToString) _itemLoc <>
135+ maybe mempty (brackets . fromText . T.pack . locationToString) _itemLoc <>
133136 fromText " " <> (unLogStr _itemMessage)
134137 where
135138 nowStr = fromText (formatAsLogTime _itemTime)
@@ -148,7 +151,7 @@ jsonFormat :: LogItem a => ItemFormatter a
148151jsonFormat withColor verb i =
149152 fromText $
150153 colorBySeverity withColor (_itemSeverity i) $
151− toStrict $ decodeUtf8 $ encode $ itemJson verb i
154+ toStrict $ TL.decodeUtf8 $ encode $ itemJson verb i
152155
153156-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
154157-- are colored red, `WarningS` is colored yellow, and all other messages are
stack.yaml+3−5
@@ -1,14 +1,12 @@
1−resolver: lts-16.18
1+resolver: lts-12.26
22packages:
33 - katip
44 - katip-elasticsearch
55 - katip-datadog
66 - katip-logzio
77extra-deps:
8− # ghc 8.8 support
9− - github: wireapp/bloodhound
10− commit: b409f52b518f20a4c20651b5893c31b7b85cb9b1
11−allow-newer: true
8+ - bloodhound-0.16.0.0
9+ - unliftio-core-0.1.2.0
1210flags:
1311 katip:
1412 lib-Werror: true