on master help sign in
cleanup and wire up the scribe
commit948052aa7e79ee0a12706f23232b03330e314143 authorAleksey Uimanov <s9gf4ult@gmail.com> dateThu 11 Jul 2019, 13:08 (7 years ago) parenta3dbdb8
4 files changed+24−4
katip/katip.cabal+1−1 katip/src/Katip.hs+1 katip/src/Katip/Scribes/Handle.hs+21 katip/src/Katip/Scribes/RotatingHandler.hs → katip/src/Katip/Scribes/Handle/FileOwner.hs+1−3
katip/katip.cabal+1−1
@@ -41,7 +41,7 @@ library
4141 , Katip.Format.Time
4242 , Katip.Monadic
4343 , Katip.Scribes.Handle
44− , Katip.Scribes.RotatingHandler
44+ , Katip.Scribes.Handle.FileOwner
4545
4646 default-extensions: DeriveGeneric
4747 , FlexibleContexts
katip/src/Katip.hs+1
@@ -182,6 +182,7 @@ module Katip
182182 , mkHandleScribeWithFormatter
183183 , mkFileScribe
184184 , mkFileScribeWithFormatter
185+ , mkFileOwnerScribeWithFormatter
185186 , ColorStrategy (..)
186187 , ItemFormatter
187188 , bracketFormat
katip/src/Katip/Scribes/Handle.hs+21
@@ -20,6 +20,7 @@ import qualified Data.HashMap.Strict as HM
2020-------------------------------------------------------------------------------
2121import Katip.Core
2222import Katip.Format.Time (formatAsLogTime)
23+import Katip.Scribes.Handle.FileOwner
2324-------------------------------------------------------------------------------
2425
2526
@@ -106,6 +107,26 @@ mkHandleScribeWithFormatter itemFormatter cs h permitF verb = do
106107 BL.hPutStr h $ toLazyByteString $ itemFormatter colorize verb i
107108 return $ Scribe logger (hFlush h) permitF
108109
110+-- | Just like mkFileScribeWithFormatter but does it with FileOwner. You can
111+-- rotate your logs with commands to the FileOwner directly. This scribe will
112+-- send messages to the given FileOwner
113+mkFileOwnerScribeWithFormatter :: (forall a . LogItem a => ItemFormatter a)
114+ -> ColorStrategy
115+ -> FileOwner
116+ -> PermitFunc
117+ -> Verbosity
118+ -> IO Scribe
119+mkFileOwnerScribeWithFormatter itemFormatter cs owner permitF verb = do
120+ let
121+ colorize = case cs of
122+ ColorIfTerminal -> False
123+ -- File is never a terminal
124+ ColorLog b -> b
125+ logger item = do
126+ writeFileOwner owner $ toLazyByteString
127+ $ itemFormatter colorize verb item
128+ scribe = Scribe logger (fileOwnerControl owner CloseMsg) permitF
129+ return scribe
109130
110131-------------------------------------------------------------------------------
111132-- | A specialization of 'mkHandleScribe' that takes a 'FilePath'
katip/src/Katip/Scribes/RotatingHandler.hs → katip/src/Katip/Scribes/Handle/FileOwner.hsrenamed+1−3
@@ -1,4 +1,4 @@
1−module Katip.Scribes.RotatingHandler where
1+module Katip.Scribes.Handle.FileOwner where
22
33import Control.Applicative
44import Control.Concurrent
@@ -106,8 +106,6 @@ newFileOwner fp s = do
106106 , foAsync = asyncRet
107107 }
108108
109−
110−
111109fileOwnerControl :: FileOwner -> ControlMsg -> IO ()
112110fileOwnerControl fo msg = do
113111 atomically $ writeTBQueue (foControlQueue fo) msg