packages feed

fluent-logger 0.2.0.0 → 0.2.1.0

raw patch · 5 files changed

+48/−14 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.md view
@@ -5,6 +5,8 @@  fluent-logger-haskell is a Haskell libraries, to record the events from Haskell application. +[![Build Status](https://travis-ci.org/notogawa/fluent-logger-haskell.svg?branch=master)](https://travis-ci.org/notogawa/fluent-logger-haskell)+ # Install  ~~~ {.bash}
fluent-logger.cabal view
@@ -1,5 +1,5 @@ name:                fluent-logger-version:             0.2.0.0+version:             0.2.1.0 synopsis:            A structured logger for Fluentd (Haskell) description:         A structured logger for Fluentd (Haskell) <http://fluentd.org/> license:             Apache-2.0
src/Network/Fluent/Logger.hs view
@@ -13,7 +13,7 @@ -- See the License for the specific language governing permissions and -- limitations under the License. ---+{-# LANGUAGE CPP #-} -- | Fluent Logger for Haskell module Network.Fluent.Logger     ( -- * Logger@@ -50,6 +50,14 @@  import Network.Fluent.Logger.Packable +-- | Wrap close / sClose (deprecated)+close :: NS.Socket -> IO ()+#if MIN_VERSION_network(2,4,0)+close = NS.close+#else+close = NS.sClose+#endif+ -- | Fluent logger settings -- -- Since 0.1.0.0@@ -104,13 +112,13 @@   setRecvTimeout sock timeout   setSendTimeout sock timeout   let onErr :: SomeException -> IO a-      onErr e = NS.sClose sock >> throwIO e+      onErr e = close sock >> throwIO e   handle onErr $ do     NS.connect sock $ NS.addrAddress addr     return sock  runSender :: FluentLoggerSender -> IO ()-runSender logger = forever $ connectFluent logger >>= sendFluent logger+runSender logger = forever $ bracket (connectFluent logger) close (sendFluent logger)  connectFluent :: FluentLoggerSender -> IO NS.Socket connectFluent logger = exponentialBackoff $ getSocket host port timeout where@@ -130,11 +138,9 @@       handle (retry $ min 60000000 $ interval * 3 `div` 2) action  sendFluent :: FluentLoggerSender -> NS.Socket -> IO ()-sendFluent logger sock = handle (done sock) toSender where+sendFluent logger sock = toSender where     chan = fluentLoggerSenderChan logger     buffered = fluentLoggerSenderBuffered logger-    done :: NS.Socket -> SomeException -> IO ()-    done = const . NS.sClose     toSender = do       entry <- atomically $ peekTChan chan       sendAll sock entry
test/MockServer.hs view
@@ -6,6 +6,7 @@     , mockServerPort     , withMockServer     , recvMockServer+    , getConnectionCount     ) where  import Data.Conduit@@ -25,6 +26,7 @@  data MockServer a = MockServer { mockServerChan :: Chan a                                , mockServerThread :: ThreadId+                               , mockServerConnectionCount :: MVar Int                                }  mockServerHost :: ByteString@@ -36,15 +38,17 @@ mockServerSettings :: ServerSettings mockServerSettings = serverSettings mockServerPort "*" -app :: (MonadIO m, MonadThrow m, Serialize a) => Chan a -> AppData -> m ()-app chan ad = appSource ad $= conduitGet get $$ sinkChan chan+app :: (MonadIO m, MonadThrow m, Serialize a) => Chan a -> MVar Int -> AppData -> m ()+app chan mvconn ad = do+  liftIO $ modifyMVar_ mvconn (return . (+ 1))+  appSource ad $= conduitGet get $$ sinkChan chan mvconn -sinkChan :: (MonadIO m, Serialize a) => Chan a -> Sink a m ()-sinkChan chan = do+sinkChan :: (MonadIO m, Serialize a) => Chan a -> MVar Int -> Sink a m ()+sinkChan chan mvconn = do   mx <- await   case mx of-    Nothing -> return ()-    Just x  -> liftIO (writeChan chan x) >> sinkChan chan+    Nothing -> liftIO $ modifyMVar_ mvconn (return . (subtract 1))+    Just x  -> liftIO (writeChan chan x) >> sinkChan chan mvconn  withMockServer :: Serialize a => (MockServer a -> IO ()) -> IO () withMockServer = bracket runMockServer stopMockServer@@ -55,13 +59,18 @@ runMockServer :: Serialize a => IO (MockServer a) runMockServer = do   chan <- newChan-  tid <- forkIO $ runTCPServer mockServerSettings $ app chan+  mvconn <- newMVar 0+  tid <- forkIO $ runTCPServer mockServerSettings $ app chan mvconn   threadDelay 10000   return MockServer { mockServerChan = chan                     , mockServerThread = tid+                    , mockServerConnectionCount = mvconn                     }  stopMockServer :: Serialize a => MockServer a -> IO () stopMockServer server = do   killThread $ mockServerThread server   threadDelay 10000++getConnectionCount :: MockServer a -> IO Int+getConnectionCount = readMVar . mockServerConnectionCount
test/Network/Fluent/LoggerSpec.hs view
@@ -22,6 +22,8 @@     -- it "losts message if buffer is over" postLostsMessageIfBufferIsOver   describe "postWithTime" $ do     it "posts a message with given time" postWithTimePostsMessageWithGivenTime+  describe "withFluentLogger" $ do+    it "disconnects when the scope is over" withFluentLoggerDisconnect   postSettings =@@ -110,3 +112,18 @@         tag `shouldBe` "postWithTime.PostsMessageWithGivenTime"         time `shouldBe` 123456         content `shouldBe` "test"++withFluentLoggerDisconnect :: IO ()+withFluentLoggerDisconnect =+  withMockServer $ \server -> do+    server `shouldHaveConns` 0+    withFluentLogger postSettings $ \logger -> do+      post logger "hoge" ("foobar" :: String)+      (tag, time, content) <- recvMockServer server :: IO (ByteString, Int, String)+      server `shouldHaveConns` 1+      tag `shouldBe` "post.hoge"+      content `shouldBe` "foobar"+    threadDelay 5000+    server `shouldHaveConns` 0+  where+    shouldHaveConns server exp = getConnectionCount server >>= (`shouldBe` exp)