on master help sign in
Merge branch 'master' into 49-queue-subscriber
commit27e91709271a6c93485968af6be78710d81efbc9 authorMichael Xavier <michael@michaelxavier.net> dateThu 6 Jul 2017, 16:11 (9 years ago) parent2f4deaf159167f
11 files changed+68−44
katip-elasticsearch/changelog.md+4 katip-elasticsearch/katip-elasticsearch.cabal+2−2 katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+1−1 katip/README.md+1 katip/changelog.md+13 katip/examples/example.hs+1−1 katip/examples/example_lens.hs+1−2 katip/katip.cabal+1−1 katip/src/Katip/Core.hs+25−11 katip/src/Katip/Monadic.hs+4−4 katip/src/Katip/Scribes/Handle.hs+15−22
katip-elasticsearch/changelog.md+4
@@ -1,3 +1,7 @@
1+0.3.1.0
2+=======
3+* Widen dependency on katip
4+
150.3.0.2
26=======
37* Loosen deps on aeson to allow 1.1.0.0
katip-elasticsearch/katip-elasticsearch.cabal+2−2
@@ -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.3.0.2
4+version: 0.3.1.0
55license: BSD3
66license-file: LICENSE
77author: Ozgun Ataman, Michael Xavier
@@ -27,7 +27,7 @@ library
2727 Katip.Scribes.ElasticSearch.Annotations
2828 build-depends:
2929 base >=4.6 && <5
30− , katip >= 0.2.0.0 && < 0.4
30+ , katip >= 0.2.0.0 && < 0.5
3131 , bloodhound >= 0.11.0.0 && < 0.13
3232 , uuid >= 1.3.12 && < 1.4
3333 , aeson >=0.6 && <1.2
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+1−1
@@ -155,7 +155,7 @@ defaultEsScribeCfg = EsScribeCfg {
155155-- advisable.
156156--
157157-- * CustomSharding: supply your own function that decomposes an item
158−-- into its index name heirarchy which will be appended to the index
158+-- into its index name hierarchy which will be appended to the index
159159-- name. So for instance if your function return ["arbitrary",
160160-- "prefix"], the index will be @foo-arbitrary-prefix@ and the index
161161-- template will be set to match @foo-*@. In general, you want to use
katip/README.md+1
@@ -83,3 +83,4 @@ stack.
8383* [Doug Beardsley](https://github.com/mightybyte)
8484* [Leonid Onokhov](https://github.com/sopvop)
8585* [Alexander Vershilov](https://github.com/qnikst)
86+* [Chris Martin](https://github.com/chris-martin)
katip/changelog.md+13
@@ -1,3 +1,16 @@
1+0.4.1.0
2+=======
3+* Add Katip instances for Strict StateT, WriterT, RWST.
4+* Add Katip instances for Lazy RWST.
5+
6+0.4.0.0
7+=======
8+* Drop unsafe _ioLogEnv for safe ioLogEnv
9+
10+0.3.1.5
11+=======
12+* Add Semigroup instance for LogStr.
13+
1140.3.1.4
215=======
316* Loosen deps on aeson to allow 1.1.0.0
katip/examples/example.hs+1−1
@@ -25,7 +25,7 @@ import Katip
2525
2626
2727-- | An example of advanced katip usage. Be sure to check out
28−-- lens_example for a slightly cleaner and more general pattern.
28+-- example_lens.hs for a slightly cleaner and more general pattern.
2929main :: IO ()
3030main = do
3131 -- We'll set up a scribe that logs to stdout and will only log item
katip/examples/example_lens.hs+1−2
@@ -40,8 +40,7 @@ makeClassy ''MyState
4040
4141
4242-------------------------------------------------------------------------------
43−-- | An example of advanced katip usage. Be sure to check out
44−-- lens_example for a slightly cleaner and more general pattern.
43+-- | An example of advanced katip usage with Lens.
4544main :: IO ()
4645main = do
4746 -- We'll set up a scribe that logs to stdout and will only log item
katip/katip.cabal+1−1
@@ -1,5 +1,5 @@
11name: katip
2−version: 0.3.1.4
2+version: 0.4.1.0
33synopsis: A structured logging framework.
44description:
55 Katip is a structured logging framework. See README.md for more details.
katip/src/Katip/Core.hs+25−11
@@ -40,13 +40,17 @@ import Control.Monad.Trans.Except
4040import Control.Monad.Trans.Maybe
4141import Control.Monad.Trans.Reader
4242import Control.Monad.Trans.Resource (ResourceT)
43−import Control.Monad.Trans.State
44−import Control.Monad.Trans.Writer
45−import Data.Aeson (FromJSON (..),
46− ToJSON (..), object)
47−import qualified Data.Aeson as A
48−import Data.Foldable as FT
49−import qualified Data.HashMap.Strict as HM
43+import Control.Monad.Trans.State.Lazy (StateT)
44+import qualified Control.Monad.Trans.State.Strict as Strict (StateT)
45+import Control.Monad.Trans.Writer.Lazy (WriterT)
46+import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT)
47+import Control.Monad.Trans.RWS.Lazy (RWST)
48+import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST)
49+import Data.Aeson (FromJSON (..), ToJSON (..),
50+ object)
51+import qualified Data.Aeson as A
52+import Data.Foldable as FT
53+import qualified Data.HashMap.Strict as HM
5054import Data.List
5155import qualified Data.Map.Strict as M
5256import Data.Semigroup
@@ -174,7 +178,7 @@ instance FromJSON Severity where
174178
175179
176180-------------------------------------------------------------------------------
177−-- | Log message with Builder unerneath; use '<>' to concat in O(1).
181+-- | Log message with Builder underneath; use '<>' to concat in O(1).
178182newtype LogStr = LogStr { unLogStr :: B.Builder }
179183 deriving (Generic, Show)
180184
@@ -198,7 +202,7 @@ instance FromJSON LogStr where
198202
199203-------------------------------------------------------------------------------
200204-- | Pack any string-like thing into a 'LogStr'. This will
201−-- automatically work on 'String', 'ByteString, 'Text' and any of the
205+-- automatically work on 'String', 'ByteString', 'Text' and any of the
202206-- lazy variants.
203207logStr :: StringConv a Text => a -> LogStr
204208logStr t = LogStr (B.fromText $ toS t)
@@ -498,7 +502,7 @@ itemJson verb a = toJSON $ a & itemPayload %~ payloadObject verb
498502-- Handle scribe does.
499503--
500504-- 2. Return a finalizing function that tells the scribe to shut
501−-- down. @katip-elasticsearch@'s @mkEsScribe@ returns a @IO (Scribe,
505+-- down. @katip-elasticsearch@'s @mkEsScribe@ returns an @IO (Scribe,
502506-- IO ())@. The finalizer will flush any queued log messages and shut
503507-- down gracefully before returning. This can be hooked into your
504508-- application's shutdown routine to ensure you never miss any log
@@ -718,14 +722,24 @@ instance Katip m => Katip (ExceptT s m) where
718722instance Katip m => Katip (MaybeT m) where
719723 getLogEnv = lift getLogEnv
720724
721−
722725instance Katip m => Katip (StateT s m) where
723726 getLogEnv = lift getLogEnv
724727
728+instance (Katip m, Monoid w) => Katip (RWST r w s m) where
729+ getLogEnv = lift getLogEnv
730+
731+instance (Katip m, Monoid w) => Katip (Strict.RWST r w s m) where
732+ getLogEnv = lift getLogEnv
733+
734+instance Katip m => Katip (Strict.StateT s m) where
735+ getLogEnv = lift getLogEnv
725736
726737instance (Katip m, Monoid s) => Katip (WriterT s m) where
727738 getLogEnv = lift getLogEnv
728739
740+instance (Katip m, Monoid s) => Katip (Strict.WriterT s m) where
741+ getLogEnv = lift getLogEnv
742+
729743instance (Katip m) => Katip (ResourceT m) where
730744 getLogEnv = lift getLogEnv
731745
katip/src/Katip/Monadic.hs+4−4
@@ -57,11 +57,11 @@ import Control.Monad.Trans.RWS (RWST)
5757import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST)
5858import qualified Control.Monad.Trans.State.Strict as Strict (StateT)
5959import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT)
60−import Control.Monad.Writer
60+import Control.Monad.Writer hiding ((<>))
6161import Data.Aeson
6262import qualified Data.Foldable as FT
6363import qualified Data.HashMap.Strict as HM
64−import Data.Monoid as M
64+import Data.Semigroup as Semi
6565import Data.Sequence as Seq
6666import Data.Text (Text)
6767import Language.Haskell.TH
@@ -93,7 +93,7 @@ data AnyLogContext where
9393-- Additional note: you should not mappend LogContexts in any sort of
9494-- infinite loop, as it retains all data, so that would be a memory
9595-- leak.
96−newtype LogContexts = LogContexts (Seq AnyLogContext) deriving (Monoid)
96+newtype LogContexts = LogContexts (Seq AnyLogContext) deriving (Monoid, Semigroup)
9797
9898instance ToJSON LogContexts where
9999 toJSON (LogContexts cs) =
@@ -231,7 +231,7 @@ logExceptionM
231231logExceptionM action sev = action `catchAny` \e -> f e >> throwM e
232232 where
233233 f e = logFM sev (msg e)
234− msg e = ls ("An exception has occured: " :: Text) M.<> showLS e
234+ msg e = ls ("An exception has occured: " :: Text) Semi.<> showLS e
235235
236236
237237-------------------------------------------------------------------------------
katip/src/Katip/Scribes/Handle.hs+15−22
@@ -3,21 +3,20 @@
33module Katip.Scribes.Handle where
44
55-------------------------------------------------------------------------------
6−import Control.Applicative as A
6+import Control.Applicative as A
77import Control.Concurrent
8−import Control.Exception (bracket_)
8+import Control.Exception (bracket_)
99import Control.Monad
1010import Data.Aeson
11−import qualified Data.HashMap.Strict as HM
11+import qualified Data.HashMap.Strict as HM
1212import Data.Monoid
13−import Data.Text (Text)
13+import Data.Text (Text)
1414import Data.Text.Lazy.Builder
15−import Data.Text.Lazy.IO as T
15+import Data.Text.Lazy.IO as T
1616import System.IO
17−import System.IO.Unsafe (unsafePerformIO)
1817-------------------------------------------------------------------------------
1918import Katip.Core
20−import Katip.Format.Time (formatAsLogTime)
19+import Katip.Format.Time (formatAsLogTime)
2120-------------------------------------------------------------------------------
2221
2322
@@ -100,18 +99,12 @@ formatItem withColor verb Item{..} =
10099 | otherwise = s
101100
102101
103−-------------------------------------------------------------------------------
104−-- | An implicit environment to enable logging directly ouf of the IO monad.
105−-- Be careful as this LogEnv won't perform any resource cleanup for you.
106−_ioLogEnv :: LogEnv
107−_ioLogEnv = unsafePerformIO $ do
108− le <- initLogEnv "io" "io"
109− lh <- mkHandleScribe ColorIfTerminal stdout DebugS V3
110− registerScribe "stdout" lh defaultScribeSettings le
111−{-# NOINLINE _ioLogEnv #-}
112−
113−
114−-- -------------------------------------------------------------------------------
115−-- -- | A default IO instance to make prototype development easy. User
116−-- -- your own 'Monad' for production.
117−-- instance Katip IO where getLogEnv = return _ioLogEnv
102+-- | Provides a simple log environment with 1 scribe going to
103+-- stdout. This is a decent example of how to build a LogEnv and is
104+-- best for scripts that just need a quick, reasonable set up to log
105+-- to stdout.
106+ioLogEnv :: Severity -> Verbosity -> IO LogEnv
107+ioLogEnv sev verb = do
108+ le <- initLogEnv "io" "io"
109+ lh <- mkHandleScribe ColorIfTerminal stdout sev verb
110+ registerScribe "stdout" lh defaultScribeSettings le