packages feed

SimpleLog 0.1.0.1 → 0.1.0.2

raw patch · 3 files changed

+45/−18 lines, 3 filesdep ~ForkableTdep ~ansi-terminaldep ~attoparsecsetup-changed

Dependency ranges changed: ForkableT, ansi-terminal, attoparsec, base, bytestring, containers, directory, monad-control, mtl, old-locale, resourcet, semigroups, stm, template-haskell, text, th-lift, time, transformers, transformers-base

Files

Setup.hs view
@@ -1,6 +1,2 @@-module Main (main) where- import Distribution.Simple--main :: IO () main = defaultMain
SimpleLog.cabal view
@@ -1,22 +1,40 @@--- Initial SimpleLog.cabal generated by cabal init.  For further --- documentation, see http://haskell.org/cabal/users-guide/- name:                SimpleLog-version:             0.1.0.1+version:             0.1.0.2 synopsis:            Simple, configurable logging description:         SimpleLog allows configurable multi-threaded logging license:             BSD3 license-file:        LICENSE author:              Andras Slemmer maintainer:          Andras Slemmer--- copyright:           +homepage:            https://github.com/exFalso/SimpleLog/ category:            System build-type:          Simple cabal-version:       >=1.8  library-  exposed-modules:     System.Log.SLog.Format, System.Log.SLog-  -- other-modules:       -  build-depends:       base ==4.6.*, transformers ==0.3.*, template-haskell ==2.8.*, bytestring ==0.10.*, attoparsec ==0.10.*, time ==1.4.*, old-locale ==1.0.*, ansi-terminal ==0.6.*, mtl ==2.1.*, stm ==2.4.*, ForkableT ==0.1.*, directory ==1.2.*, containers ==0.5.*, resourcet ==0.4.*, transformers-base ==0.4.*, monad-control ==0.3.*, text ==0.11.*, th-lift ==0.5.*, semigroups ==0.9.*+  exposed-modules:     System.Log.SLog.Format,+                       System.Log.SLog+  build-depends:       base < 5 && >= 4,+                       transformers < 1,+                       template-haskell < 3 && >= 2,+                       bytestring < 1,+                       attoparsec < 1,+                       time < 2 && >= 1,+                       old-locale < 2 && >= 1,+                       ansi-terminal < 1,+                       mtl < 3 && >= 2,+                       stm < 3 && >= 2,+                       ForkableT < 1,+                       directory < 2 && >= 1,+                       containers < 1,+                       resourcet < 2 && >= 1,+                       transformers-base < 1,+                       monad-control < 1,+                       text < 2 && >= 1,+                       th-lift < 1,+                       semigroups < 1   hs-source-dirs:      src +source-repository head+  type:              git+  location:          git@github.com:exFalso/SimpleLog.git
src/System/Log/SLog.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE GeneralizedNewtypeDeriving, DefaultSignatures, ScopedTypeVariables, NamedFieldPuns, OverloadedStrings, MultiParamTypeClasses, TemplateHaskell, FlexibleContexts, TypeFamilies, StandaloneDeriving, RecordWildCards, Trustworthy #-}+{-# LANGUAGE GeneralizedNewtypeDeriving, DefaultSignatures, ScopedTypeVariables, NamedFieldPuns, OverloadedStrings, MultiParamTypeClasses, TemplateHaskell, FlexibleContexts, TypeFamilies, StandaloneDeriving, RecordWildCards, RankNTypes, Trustworthy, UndecidableInstances #-} {-|   SimpleLog is a library for convenient and configurable logging. It uses the usual monad transformer + associated class design: 'SLogT' and 'MonadSLog'. @@ -127,6 +127,7 @@     -- * Utility functions     , forkSLog     , formatLine+    , unsafeUnliftSLogT     ) where @@ -286,8 +287,9 @@ newtype SLogT m a     = SLogT { unSLogT :: ReaderT SLogEnv (ResourceT m) a }       deriving ( Functor, Monad, MonadIO, Applicative-               , MonadThrow, MonadResource )+               , MonadThrow ) deriving instance (MonadBase IO m) => MonadBase IO (SLogT m)+deriving instance (MonadBase IO m, MonadThrow m, MonadIO m) => MonadResource (SLogT m)  instance MonadTransControl SLogT where     newtype StT SLogT a = StTSLogT {unStTSLogT :: StT ResourceT a}@@ -331,7 +333,7 @@ -- finish before the FlushKey releases -- | 'runSLogT' runs an 'SLogT' given a 'LogConfig', 'Format' and the current thread's name. -- It returns a 'FlushKey' besides the usual return value.-runSLogT :: (MonadIO m, MonadThrow m, MonadUnsafeIO m, Applicative m, MonadBaseControl IO m) => LogConfig -> Format -> String -> SLogT m a -> m (a, FlushKey)+runSLogT :: (MonadResource m, MonadBaseControl IO m) => LogConfig -> Format -> String -> SLogT m a -> m (a, FlushKey) runSLogT LogConfig{..} lf tName (SLogT r)     = runResourceT $ do         (_, tvar) <- allocate (newTVarIO False) (\t -> atomically $ writeTVar t True)@@ -344,7 +346,7 @@           return (a, FlushKey tvar)  -- | 'simpleLog' uses the default configuration with the specified log file name. It also waits using 'waitFlush' until all resources have been released.-simpleLog :: (MonadIO m, MonadUnsafeIO m, MonadThrow m, Applicative m, MonadBaseControl IO m) => FilePath -> SLogT m a -> m a+simpleLog :: (MonadResource m, MonadBaseControl IO m) => FilePath -> SLogT m a -> m a simpleLog fName s = do   tName <- show <$> liftIO myThreadId   (a, fkey) <- runSLogT (defaultLogConfig fName) defaultLogFormat tName s@@ -354,7 +356,7 @@ -- | initLoggers initialises the user specified 'Logger's and returns the internal representation of them. --  -- This includes first aggregating the 'Logger's resolving any ambiguities, then opening the logging streams.-initLoggers :: (MonadIO m, MonadThrow m, MonadUnsafeIO m, Applicative m) => [(Filter, Logger)] -> ResourceT (ResourceT m) [(Filter, LoggerInternal)]+initLoggers :: (MonadResource m, Applicative m) => [(Filter, Logger)] -> ResourceT (ResourceT m) [(Filter, LoggerInternal)] initLoggers fls = do   InitState{..} <- liftIO $ aggregateLoggers fls @@ -416,7 +418,7 @@  -- | 'forkCleanup' forks a ResIO thread that will get an exit signal through a TVar when the outer ResourceT is run. -- The forked off ResourceT is the inner one-forkCleanUp :: (MonadIO m, MonadThrow m, MonadUnsafeIO m, Applicative m) =>+forkCleanUp :: (MonadResource m) =>                (TVar Bool -> ResIO ()) -> ResourceT (ResourceT m) ThreadId forkCleanUp io = do   (_, exitSignal) <- allocate (newTVarIO False) (\t -> atomically $ writeTVar t True)@@ -517,6 +519,17 @@ -- | helper method for padding with spaces padS :: Int -> T.Text -> T.Text padS n t = t `T.append` T.replicate (n - T.length t) " "++-- | 'unsafeUnliftSLog' gives you an unsafe unlift of an SLogT by assuming that any unlifted computation will finish earlier than the runSLogT of the calling thread.+-- It is unsafe because if the unlifted computation doesn't finish earlier then it may access deallocated resources.+-- This is useful when a library is implicitly forking but we still need to log in the forked threads, and we know that the child threads will finish earlier than the parent. An example is Network.WebSockets+unsafeUnliftSLogT :: forall m b. (Monad m, MonadBaseControl IO m) =>+                    ((forall a. SLogT m a -> m a) -> SLogT m b) -> SLogT m b+unsafeUnliftSLogT f = do+  env <- SLogT ask+  let unlift :: SLogT m c -> m c+      unlift s = runResourceT $ runReaderT (unSLogT s) env+  f unlift  instance (MonadIO m) => MonadSLog (SLogT m) where     log sev s = do