graflog (empty) → 0.1.0
raw patch · 7 files changed
+151/−0 lines, 7 filesdep +aesondep +basedep +bytestringsetup-changed
Dependencies added: aeson, base, bytestring, graflog, hspec, mtl, test-fixture, text, text-conversions
Files
- LICENSE +30/−0
- README.md +3/−0
- Setup.hs +2/−0
- graflog.cabal +42/−0
- src/Graflog/Console.hs +20/−0
- src/Graflog/Logger.hs +53/−0
- test/Spec.hs +1/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Michael Adlai Arnold (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Michael Adlai Arnold nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# Graflog++Monadic correlated log events!
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ graflog.cabal view
@@ -0,0 +1,42 @@+name: graflog+version: 0.1.0+synopsis: Monadic correlated log events+description: Please see README.md+homepage: https://github.com/m-arnold/graflog#readme+license: BSD3+license-file: LICENSE+author: Michael Adlai Arnold+maintainer: marnold@cj.com+copyright: 2016 Michael A. Arnold+category: Development+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Graflog.Logger, Graflog.Console+ build-depends: base >= 4.7 && < 5+ , text-conversions+ , text+ , aeson+ , bytestring+ default-language: Haskell2010+ default-extensions: GeneralizedNewtypeDeriving++test-suite graflog-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: base+ , graflog+ , test-fixture+ , hspec+ , mtl+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ default-language: Haskell2010+ default-extensions: ConstraintKinds DeriveGeneric FlexibleContexts FlexibleInstances GADTs GeneralizedNewtypeDeriving KindSignatures LambdaCase MultiParamTypeClasses NamedFieldPuns OverloadedStrings RankNTypes ScopedTypeVariables TypeOperators DuplicateRecordFields++source-repository head+ type: git+ location: https://github.com/m-arnold/graflog
+ src/Graflog/Console.hs view
@@ -0,0 +1,20 @@+module Graflog.Console+ ( Console(..)+ , writeStdout'+ , enableStdoutLineBuffering+ ) where++import Control.Monad.IO.Class (MonadIO(liftIO))+import Data.Text (Text)+import qualified Data.Text.IO as T (putStrLn)+import System.IO (hSetBuffering, stdout, BufferMode(..))++class Monad m => Console m where+ writeStdout :: Text -> m ()++writeStdout' :: MonadIO m => Text -> m ()+writeStdout' = liftIO . T.putStrLn++-- this function forces stdout into line buffering mode; useful for CloudFormation logs+enableStdoutLineBuffering :: MonadIO m => m ()+enableStdoutLineBuffering = liftIO $ hSetBuffering stdout LineBuffering
+ src/Graflog/Logger.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}++module Graflog.Logger+ ( Logger(..)+ , Event(..)+ , CorrelationId(..)+ , EventId(..)+ , Action(..)+ , logEvent'+ , jsonEncode+ ) where++import Data.Aeson (ToJSON, FromJSON, encode)+import Data.Aeson.TH (deriveJSON, defaultOptions, fieldLabelModifier)+import Data.ByteString (ByteString)+import Data.ByteString.Lazy (toStrict)+import Data.Maybe (fromJust)+import Data.String (IsString)+import Data.Text (Text)+import Data.Text.Conversions (decodeConvertText, UTF8(..))++import Graflog.Console++class Monad m => Logger m where+ logEvent :: Event -> m ()++newtype CorrelationId = CorrelationId Integer+ deriving (Eq, Show, Num, FromJSON, ToJSON)++newtype EventId = EventId Integer+ deriving (Eq, Show, Num, FromJSON, ToJSON)++newtype Action = Action Text+ deriving (Eq, Show, IsString, FromJSON, ToJSON)++data Event = Event+ { _correlationId :: CorrelationId+ , _eventId :: EventId+ , _action :: Action+ , _message :: Text+ } deriving (Eq, Show)++deriveJSON defaultOptions{fieldLabelModifier = drop 1} ''Event++logEvent' :: Console m => Event -> m ()+logEvent' = writeStdout . jsonEncode++-- this will always work b/c UTF8 spec+jsonEncode :: ToJSON a => a -> Text+jsonEncode = byteStringToText . toStrict . encode+ where byteStringToText :: ByteString -> Text+ byteStringToText bs = fromJust $ decodeConvertText (UTF8 (bs :: ByteString))
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}