packages feed

conlogger (empty) → 0.1.0.0

raw patch · 5 files changed

+104/−0 lines, 5 filesdep +basedep +conloggerdep +textsetup-changed

Dependencies added: base, conlogger, text

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 tattsun++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ conlogger.cabal view
@@ -0,0 +1,34 @@+-- Initial conlogger.cabal generated by cabal init.  For further+-- documentation, see http://haskell.org/cabal/users-guide/++name:                conlogger+version:             0.1.0.0+synopsis:            A logger for a concurrent program.+-- description:+license:             MIT+license-file:        LICENSE+author:              tattsun+maintainer:          t.t.mc1192.sf@gmail.com+-- copyright:+category:            Concurrency+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  exposed-modules:     Control.Concurrent.ConLogger+  -- other-modules:+  -- other-extensions:+  ghc-options:         -O2 -Wall+  build-depends:       base >=4.7 && <4.8+                     , text >= 1.1.0.0+  hs-source-dirs:      src+  default-language:    Haskell2010++executable "example"+  build-depends:       base >= 4.7 && <4.8+                     , conlogger == 0.1.0.0+                     , text >= 1.1.0.0+  hs-source-dirs:      examples+  main-is:             Main.hs+  default-language:    Haskell2010
+ examples/Main.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE OverloadedStrings #-}+module Main where++import           Control.Concurrent+import qualified Control.Concurrent.ConLogger as Log+import           Control.Monad+import qualified Data.Text                    as T++main :: IO ()+main = do+  logger <- Log.new+  replicateM_ 100 (thread logger)+  Log.put logger "Main"++thread :: Log.ConLogger -> IO ()+thread logger = replicateM_ 50 (Log.put logger "Thread")
+ src/Control/Concurrent/ConLogger.hs view
@@ -0,0 +1,32 @@+module Control.Concurrent.ConLogger+       ( ConLogger+       , new+       , put+       ) where++import           Control.Applicative+import           Control.Concurrent      (forkIO)+import           Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)+import           Control.Monad           (void)+import qualified Data.Text               as T (Text)+import qualified Data.Text.IO            as T (putStrLn)+import           Prelude                 hiding (log)++newtype ConLogger = ConLogger { conLogger :: Chan T.Text }++new :: IO ConLogger+new = do+  ch <- ConLogger <$> newChan+  void $ forkIO (runner ch)+  return ch++put :: ConLogger -> T.Text -> IO ()+put cl = writeChan (conLogger cl)++runner :: ConLogger -> IO ()+runner cl = do+  log <- readChan chan+  T.putStrLn log+  runner cl+  where+    chan = conLogger cl