<commit_before>-- |
-- Module      : Numbers.Conduit.Log
-- Copyright   : (c) 2012 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--

module Numbers.Conduit.Log (
      logSink
    ) where

import Control.Monad.IO.Class (liftIO)
import Data.List              (intercalate)
import Numbers.Log
import Numbers.Conduit.Internal
import Numbers.Types

logSink :: [String] -> Maybe (IO EventSink)
logSink [] = Nothing
logSink es = Just $ do
    infoL $ "Logging " <&& intercalate ", " es &&> " events"
    runSink $ awaitForever f =$ awaitForever (liftIO . infoL)
  where
    f (Flush ts p) = yield $ p &&> " " &&& ts &&> "\n"
    f _            = return ()


<commit_msg>Removing extraneous newline in the log sink<commit_after>-- |
-- Module      : Numbers.Conduit.Log
-- Copyright   : (c) 2012 <NAME> <<EMAIL>>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--

module Numbers.Conduit.Log (
      logSink
    ) where

import Control.Monad.IO.Class (liftIO)
import Data.List              (intercalate)
import Numbers.Log
import Numbers.Conduit.Internal
import Numbers.Types

logSink :: [String] -> Maybe (IO EventSink)
logSink [] = Nothing
logSink es = Just $ do
    infoL $ "Logging " <&& intercalate ", " es &&> " events"
    runSink $ awaitForever f =$ awaitForever (liftIO . infoL)
  where
    f (Flush ts p) = yield $ p &&> " " &&& ts
    f _            = return ()



{'fraction_non_alphanumeric': 0.1292550567340898, 'fraction_numerical': 0.007893438579181056, 'mean_word_length': 2.260450160771704, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5418929', 'n_tokens_mistral': 667, 'n_tokens_neox': 645, 'n_words': 209}