on 143ee56 help sign in
23 files changed+262−224
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+29−28 katip/src/Katip.hs+1−1 katip/src/Katip/Core.hs+19−36 katip/src/Katip/Monadic.hs+6−20 katip/src/Katip/Scribes/Handle.hs+43−26 katip/src/Katip/Scribes/RotatingHandler.hs+118 katip/test/Katip/Tests/Scribes/Handle.hs+6−8 stack.yaml+6−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+29−28
@@ -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.
@@ -36,22 +36,22 @@ flag lib-Werror
3636 manual: True
3737
3838library
39− exposed-modules:
40− Katip
41− Katip.Core
42− Katip.Format.Time
43− Katip.Monadic
44− Katip.Scribes.Handle
39+ exposed-modules: Katip
40+ , Katip.Core
41+ , Katip.Format.Time
42+ , Katip.Monadic
43+ , Katip.Scribes.Handle
44+ , Katip.Scribes.RotatingHandler
4545
46− default-extensions:
47− DeriveGeneric
48− FlexibleContexts
49− GeneralizedNewtypeDeriving
50− MultiParamTypeClasses
51− RankNTypes
52− RecordWildCards
53− TemplateHaskell
54− OverloadedStrings
46+ default-extensions: DeriveGeneric
47+ , FlexibleContexts
48+ , GeneralizedNewtypeDeriving
49+ , LambdaCase
50+ , MultiParamTypeClasses
51+ , OverloadedStrings
52+ , RankNTypes
53+ , RecordWildCards
54+ , TemplateHaskell
5555
5656 build-depends: base >=4.9.0.0 && <5
5757 , aeson >=0.6
@@ -59,27 +59,28 @@ library
5959 , auto-update >= 0.1
6060 , bytestring >= 0.9
6161 , containers >=0.4
62+ , deepseq
6263 , either >= 4
63− , safe-exceptions >= 0.1.0.0
6464 , hostname >=1.0
65+ , microlens >= 0.2.0.0
66+ , microlens-th >= 0.1.0.0
67+ , monad-control >= 1.0
68+ , mtl >= 2.0
6569 , old-locale >= 1.0
70+ , resourcet >= 1.1
71+ , safe-exceptions >= 0.1.0.0
72+ , scientific >= 0.3.3.0
73+ , semigroups
74+ , stm >= 2.4 && < 2.5
6675 , string-conv >= 0.1
6776 , template-haskell >= 2.8
6877 , text >= 0.11
6978 , time >= 1
7079 , transformers >= 0.3
71− , transformers-compat
72− , unordered-containers >= 0.2
73− , monad-control >= 1.0
74− , mtl >= 2.0
7580 , transformers-base >= 0.3
76− , resourcet >= 1.1
77− , scientific >= 0.3.3.0
78− , microlens >= 0.2.0.0
79− , microlens-th >= 0.1.0.0
80− , semigroups
81+ , transformers-compat
8182 , unliftio-core >= 0.1
82− , stm >= 2.4
83+ , unordered-containers >= 0.2
8384
8485 hs-source-dirs: src
8586 default-language: Haskell2010
@@ -87,7 +88,7 @@ library
8788 if flag(lib-Werror)
8889 ghc-options: -Werror
8990 if os(windows)
90− build-depends: Win32 >=2.3 && <2.9
91+ build-depends: Win32 >=2.3 && <2.6
9192 exposed-modules: Katip.Compat
9293 else
9394 build-depends: unix >= 2.5 && <2.8
katip/src/Katip.hs+1−1
@@ -161,7 +161,6 @@ module Katip
161161 , logT
162162 , logLoc
163163 , logItem
164− , logKatipItem
165164 , logException
166165 -- ** 'KatipContext': Logging With Context
167166 -- $katipcontextlogging
@@ -182,6 +181,7 @@ module Katip
182181 , mkHandleScribe
183182 , mkHandleScribeWithFormatter
184183 , mkFileScribe
184+ , mkFileScribeWithFormatter
185185 , ColorStrategy (..)
186186 , ItemFormatter
187187 , bracketFormat
katip/src/Katip/Core.hs+19−36
@@ -44,8 +44,7 @@ import Control.Monad.Trans.Either
4444import Control.Monad.Trans.Except
4545import Control.Monad.Trans.Maybe
4646import Control.Monad.Trans.Reader
47−import Control.Monad.Trans.Resource (MonadResource, ResourceT,
48− transResourceT)
47+import Control.Monad.Trans.Resource (ResourceT, transResourceT)
4948import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
5049import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
5150import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
@@ -665,7 +664,7 @@ makeLenses ''LogEnv
665664
666665
667666-------------------------------------------------------------------------------
668−-- | Create a reasonable default InitLogEnv. Uses an 'AutoUpdate' which
667+-- | Create a reasonable default InitLogEnv. Uses an 'AutoUdate' which
669668-- updates the timer every 1ms. If you need even more timestamp
670669-- precision at the cost of performance, consider setting
671670-- '_logEnvTimer' with 'getCurrentTime'.
@@ -880,8 +879,7 @@ instance (Katip m) => Katip (ResourceT m) where
880879-- opposed to implementing 'Katip' for your monad.
881880newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
882881 deriving ( Functor, Applicative, Monad, MonadIO
883− , MonadMask, MonadCatch, MonadThrow, MonadResource, MonadTrans
884− , MonadBase b)
882+ , MonadMask, MonadCatch, MonadThrow, MonadTrans, MonadBase b)
885883
886884
887885instance MonadIO m => Katip (KatipT m) where
@@ -903,14 +901,9 @@ instance (MonadBaseControl b m) => MonadBaseControl b (KatipT m) where
903901 restoreM = defaultRestoreM
904902
905903instance 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
910904 askUnliftIO = KatipT $
911− withUnliftIO $ \u ->
912− pure (UnliftIO (unliftIO u . unKatipT))
913−#endif
905+ withUnliftIO $ \u ->
906+ pure (UnliftIO (unliftIO u . unKatipT))
914907
915908#if MIN_VERSION_base(4, 9, 0)
916909instance MF.MonadFail m => MF.MonadFail (KatipT m) where
@@ -948,29 +941,19 @@ logItem
948941 -> m ()
949942logItem a ns loc sev msg = do
950943 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 $
944+ liftIO $ do
945+ item <- Item
946+ <$> pure _logEnvApp
947+ <*> pure _logEnvEnv
948+ <*> pure sev
949+ <*> (mkThreadIdText <$> myThreadId)
950+ <*> pure _logEnvHost
951+ <*> pure _logEnvPid
952+ <*> pure a
953+ <*> pure msg
954+ <*> _logEnvTimer
955+ <*> pure (_logEnvApp <> ns)
956+ <*> pure loc
974957 FT.forM_ (M.elems _logEnvScribes) $ \ ScribeHandle {..} -> do
975958 whenM (scribePermitItem shScribe item) $
976959 void $ atomically (tryWriteTBQueue shChan (NewItem item))
@@ -1019,7 +1002,7 @@ logException
10191002logException a ns sev action = action `catchAny` \e -> f e >> throwM e
10201003 where
10211004 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
10231006
10241007
10251008-------------------------------------------------------------------------------
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+43−26
@@ -3,17 +3,20 @@ module Katip.Scribes.Handle where
33-------------------------------------------------------------------------------
44import Control.Applicative as A
55import Control.Concurrent
6−import Control.Exception (bracket_, finally)
6+import Control.Exception (finally)
77import Data.Aeson
8−import Data.Text.Lazy (toStrict)
9−import Data.Text.Lazy.Encoding (decodeUtf8)
10−import qualified Data.HashMap.Strict as HM
8+import Data.Aeson.Text
9+import Data.ByteString.Builder as B
10+import Data.ByteString.Lazy as BL (hPutStr)
11+import Data.ByteString.Lazy.Char8 as BL (singleton)
1112import Data.Monoid as M
1213import Data.Scientific as S
1314import Data.Text (Text)
14−import Data.Text.Lazy.Builder
15−import Data.Text.Lazy.IO as T
15+import Data.Text.Lazy.Builder as TL
16+import Data.Text.Lazy.Encoding (encodeUtf8)
1617import System.IO
18+import qualified Data.HashMap.Strict as HM
19+
1720-------------------------------------------------------------------------------
1821import Katip.Core
1922import Katip.Format.Time (formatAsLogTime)
@@ -21,15 +24,20 @@ import Katip.Format.Time (formatAsLogTime)
2124
2225
2326-------------------------------------------------------------------------------
24−brackets :: Builder -> Builder
27+brackets :: TL.Builder -> TL.Builder
2528brackets m = fromText "[" M.<> m <> fromText "]"
2629
30+textBuilderToBS :: TL.Builder -> B.Builder
31+textBuilderToBS = B.lazyByteString . encodeUtf8 . toLazyText
32+
33+appendNL :: B.Builder -> B.Builder
34+appendNL b = b <> B.lazyByteString (BL.singleton '\n')
2735
2836-------------------------------------------------------------------------------
29−getKeys :: LogItem s => Verbosity -> s -> [Builder]
37+getKeys :: LogItem s => Verbosity -> s -> [TL.Builder]
3038getKeys verb a = concat (renderPair A.<$> HM.toList (payloadObject verb a))
3139 where
32− renderPair :: (Text, Value) -> [Builder]
40+ renderPair :: (Text, Value) -> [TL.Builder]
3341 renderPair (k,v) =
3442 case v of
3543 Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- HM.toList o]
@@ -65,6 +73,19 @@ data ColorStrategy
6573mkHandleScribe :: ColorStrategy -> Handle -> PermitFunc -> Verbosity -> IO Scribe
6674mkHandleScribe = mkHandleScribeWithFormatter bracketFormat
6775
76+
77+mkFileScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
78+ -> ColorStrategy
79+ -> FilePath
80+ -> PermitFunc
81+ -> Verbosity
82+ -> IO Scribe
83+mkFileScribeWithFormatter formatter color f permitF verb = do
84+ h <- openBinaryFile f AppendMode
85+ Scribe logger finalizer permit <- mkHandleScribeWithFormatter formatter color h permitF verb
86+ return (Scribe logger (finalizer `finally` hClose h) permit)
87+
88+
6889-- | Logs to a file handle such as stdout, stderr, or a file. Takes a custom
6990-- `ItemFormatter` that can be used to format `Item` as needed.
7091--
@@ -77,14 +98,12 @@ mkHandleScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
7798 -> Verbosity
7899 -> IO Scribe
79100mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
80− hSetBuffering h LineBuffering
81101 colorize <- case cs of
82102 ColorIfTerminal -> hIsTerminalDevice h
83103 ColorLog b -> return b
84104 lock <- newMVar ()
85− let logger i@Item{..} = do
86− bracket_ (takeMVar lock) (putMVar lock ()) $
87− T.hPutStrLn h $ toLazyText $ itemFormatter colorize verb i
105+ let logger i@Item{..} = withMVar lock $ \() -> do
106+ BL.hPutStr h $ toLazyByteString $ itemFormatter colorize verb i
88107 return $ Scribe logger (hFlush h) permitF
89108
90109
@@ -95,19 +114,17 @@ mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
95114-- 'closeScribe'/'closeScribes'. Does not do log coloring. Sets handle
96115-- to 'LineBuffering' mode.
97116mkFileScribe :: FilePath -> PermitFunc -> Verbosity -> IO Scribe
98−mkFileScribe f permitF verb = do
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)
117+mkFileScribe = mkFileScribeWithFormatter bracketFormat (ColorLog False)
102118
103119
104120-------------------------------------------------------------------------------
105121-- | A custom ItemFormatter for logging `Item`s. Takes a `Bool` indicating
106122-- whether to colorize the output, `Verbosity` of output, and an `Item` to
107−-- format.
123+-- format. Note that formatter is responsible for appending the newline at the
124+-- end of the string if required
108125--
109126-- See `bracketFormat` and `jsonFormat` for examples.
110−type ItemFormatter a = Bool -> Verbosity -> Item a -> Builder
127+type ItemFormatter a = Bool -> Verbosity -> Item a -> B.Builder
111128
112129
113130formatItem :: LogItem a => ItemFormatter a
@@ -121,10 +138,10 @@ formatItem = bracketFormat
121138-- > [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
122139-- > [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
123140bracketFormat :: LogItem a => ItemFormatter a
124−bracketFormat withColor verb Item{..} =
141+bracketFormat withColor verb Item{..} = appendNL $ textBuilderToBS $
125142 brackets nowStr <>
126143 brackets (mconcat $ map fromText $ intercalateNs _itemNamespace) <>
127− brackets (fromText (renderSeverity' _itemSeverity)) <>
144+ brackets (renderSeverity' _itemSeverity) <>
128145 brackets (fromString _itemHost) <>
129146 brackets ("PID " <> fromString (show _itemProcess)) <>
130147 brackets ("ThreadId " <> fromText (getThreadIdText _itemThread)) <>
@@ -135,7 +152,7 @@ bracketFormat withColor verb Item{..} =
135152 nowStr = fromText (formatAsLogTime _itemTime)
136153 ks = map brackets $ getKeys verb _itemPayload
137154 renderSeverity' severity =
138− colorBySeverity withColor severity (renderSeverity severity)
155+ colorBySeverity withColor severity (fromText $ renderSeverity severity)
139156
140157-- | Logs items as JSON. This can be useful in circumstances where you already
141158-- have infrastructure that is expecting JSON to be logged to a standard stream
@@ -145,15 +162,15 @@ bracketFormat withColor verb Item{..} =
145162-- > {"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"}
146163-- > {"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"}
147164jsonFormat :: LogItem a => ItemFormatter a
148−jsonFormat withColor verb i =
149− fromText $
165+jsonFormat withColor verb i = appendNL $
166+ textBuilderToBS $
150167 colorBySeverity withColor (_itemSeverity i) $
151− toStrict $ decodeUtf8 $ encode $ itemJson verb i
168+ encodeToTextBuilder $ itemJson verb i
152169
153170-- | Color a text message based on `Severity`. `ErrorS` and more severe errors
154171-- are colored red, `WarningS` is colored yellow, and all other messages are
155172-- rendered in the default color.
156−colorBySeverity :: Bool -> Severity -> Text -> Text
173+colorBySeverity :: Bool -> Severity -> TL.Builder -> TL.Builder
157174colorBySeverity withColor severity msg = case severity of
158175 EmergencyS -> red msg
159176 AlertS -> red msg
katip/src/Katip/Scribes/RotatingHandler.hsnew file+118
@@ -0,0 +1,118 @@
1+module Katip.Scribes.RotatingHandler where
2+
3+import Control.Applicative
4+import Control.Concurrent.Async
5+import Control.Concurrent.STM
6+import Control.Debounce
7+import Control.DeepSeq
8+import Control.Exception
9+import Control.Monad
10+import Data.ByteString.Lazy as BL
11+import Data.IORef
12+import GHC.IO.Handle
13+import GHC.IO.Handle.FD
14+import GHC.IO.IOMode
15+
16+-- | File owner struct writing data to the file
17+-- sequentially. Automatic buffer flushing and log rotating.
18+data FileOwner = FileOwner
19+ { foDataQueune :: TBQueue BL.ByteString
20+ , foControlQueue :: TBQueue ControlMsg
21+ , foAsync :: Async ()
22+ -- ^ Wait for to be sure that worker thread is closed.
23+ }
24+
25+data FileOwnerSettings = FileOwnerSettings
26+ { fosDebounceFreq :: Maybe Int
27+ , fosDataQueueLen :: Int
28+ , fosControlQueueLen :: Int
29+ }
30+
31+defaultFileOwnerSettings :: FileOwnerSettings
32+defaultFileOwnerSettings = FileOwnerSettings
33+ { fosDebounceFreq = Just 200000 -- every 200ms
34+ , fosDataQueueLen = 1000
35+ , fosControlQueueLen = 100
36+ }
37+
38+data ControlMsg
39+ = CloseMsg
40+ | FlushMsg
41+ | ReopenMsg
42+ deriving (Eq, Ord, Show)
43+
44+newFileOwner :: FilePath -> FileOwnerSettings -> IO FileOwner
45+newFileOwner fp s = do
46+ dqueue <- newTBQueueIO $ fosDataQueueLen s
47+ cqueue <- newTBQueueIO $ fosControlQueueLen s
48+ let
49+ newResource = do
50+ openBinaryFile fp AppendMode
51+ ack = newResource >>= newIORef
52+ release ref = do
53+ h <- readIORef ref
54+ hFlush h
55+ hClose h
56+ go ref = do
57+ let
58+ readAllData = do
59+ a <- readTBQueue dqueue
60+ -- flushTBQueue never retries
61+ as <- flushTBQueue dqueue
62+ return $ a:as
63+ readMsg
64+ = (Left <$> readTBQueue cqueue)
65+ <|> (Right <$> readAllData)
66+ debounce action = case fosDebounceFreq s of
67+ Nothing -> do
68+ return action
69+ Just freq -> mkDebounce $ defaultDebounceSettings
70+ { debounceAction = action
71+ , debounceFreq = freq }
72+ flush <- debounce $ readIORef ref >>= hFlush
73+ let
74+ recur = atomically readMsg >>= \case
75+ Right bs -> do
76+ h <- readIORef ref
77+ BL.hPutStr h $ mconcat bs
78+ flush
79+ recur
80+ Left c -> case c of
81+ CloseMsg -> return () -- release will close the handler
82+ FlushMsg -> do
83+ readIORef ref >>= hFlush
84+ recur
85+ ReopenMsg -> do
86+ newH <- newResource
87+ oldH <- atomicModifyIORef' ref (\oldH -> (newH, oldH))
88+ hFlush oldH
89+ hClose oldH
90+ recur
91+ recur
92+ worker :: IO ()
93+ worker = bracket ack release go
94+ asyncRet <- async worker
95+ return $ FileOwner
96+ { foDataQueune = dqueue
97+ , foControlQueue = cqueue
98+ , foAsync = asyncRet
99+ }
100+
101+
102+
103+fileOwnerControl :: FileOwner -> ControlMsg -> IO ()
104+fileOwnerControl fo msg = do
105+ atomically $ writeTBQueue (foControlQueue fo) msg
106+ when (msg == CloseMsg) $ do
107+ -- Wait for worker thread to finish
108+ void $ waitCatch $ foAsync fo
109+
110+writeFileOwner :: FileOwner -> BL.ByteString -> IO ()
111+writeFileOwner fo bs = do
112+ a <- return $!! bs
113+ -- The deepseq here is to be sure that writing thread will not
114+ -- calculate thunks and will not get into the blackhole or
115+ -- something. Precalculating is the responsibility of the sending
116+ -- thread, because there may be several sending threads and only one
117+ -- writing.
118+ atomically $ writeTBQueue (foDataQueune fo) $!! a
katip/test/Katip/Tests/Scribes/Handle.hs+6−8
@@ -1,5 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE RankNTypes #-}
2+{-# LANGUAGE RankNTypes #-}
33module Katip.Tests.Scribes.Handle
44 ( tests
55 ) where
@@ -7,12 +7,11 @@ module Katip.Tests.Scribes.Handle
77-------------------------------------------------------------------------------
88import Control.Monad
99import Data.Aeson
10−import qualified Data.ByteString.Char8 as B
10+import Data.ByteString.Builder as B
1111import qualified Data.ByteString.Lazy as BL
1212import Data.Monoid as M
1313import Data.Text (Text)
1414import qualified Data.Text as T
15−import qualified Data.Text.Encoding as T
1615import qualified Data.Text.Lazy as LT
1716import qualified Data.Text.Lazy.Builder as LT
1817import Data.Time
@@ -245,14 +244,13 @@ writeJsonLog = writeFormattedLog jsonFormat
245244
246245writeFormattedLog :: (forall a . LogItem a => ItemFormatter a) -> (FilePath, Handle) -> IO (BL.ByteString)
247246writeFormattedLog format (path, h) = do
248− mapM_ (put . formatOne) genItems
249− mapM_ (put . formatOne) genTypedItems
247+ mapM_ put genItems
248+ mapM_ put genTypedItems
250249 hClose h
251250 BL.readFile path
252251 where
253− formatOne :: LogItem a => Item a -> Text
254− formatOne = LT.toStrict . LT.toLazyText . format False V3
255− put = B.hPutStrLn h . T.encodeUtf8
252+ put :: (LogItem a) => Item a -> IO ()
253+ put = BL.hPutStr h . toLazyByteString . format False V3
256254
257255setupTempFile :: IO (FilePath, Handle)
258256setupTempFile = do
stack.yaml+6−5
@@ -1,14 +1,15 @@
1−resolver: lts-16.18
1+nix:
2+ packages:
3+ - zlib
4+resolver: lts-12.26
25packages:
36 - katip
47 - katip-elasticsearch
58 - katip-datadog
69 - katip-logzio
710extra-deps:
8− # ghc 8.8 support
9− - github: wireapp/bloodhound
10− commit: b409f52b518f20a4c20651b5893c31b7b85cb9b1
11−allow-newer: true
11+ - bloodhound-0.16.0.0
12+ - unliftio-core-0.1.2.0
1213flags:
1314 katip:
1415 lib-Werror: true