packages feed

log-effectful (empty) → 1.0.0.0

raw patch · 6 files changed

+222/−0 lines, 6 filesdep +aesondep +basedep +effectful-core

Dependencies added: aeson, base, effectful-core, log-base, log-effectful, text, time

Files

+ CHANGELOG.md view
@@ -0,0 +1,2 @@+# log-effectful-1.0.0.0 (2022-10-10)+* Initial release.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2021 Hécate Moonlight++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.
+ README.md view
@@ -0,0 +1,35 @@+# log-effectful++[![Build Status](https://github.com/haskell-effectful/log-effectful/workflows/Haskell-CI/badge.svg?branch=master)](https://github.com/haskell-effectful/log-effectful/actions?query=branch%3Amaster)+[![Hackage](https://img.shields.io/hackage/v/log-effectful.svg)](https://hackage.haskell.org/package/log-effectful)+[![Dependencies](https://img.shields.io/hackage-deps/v/log-effectful.svg)](https://packdeps.haskellers.com/feed?needle=andrzej@rybczak.net)+[![Stackage LTS](https://www.stackage.org/package/log-effectful/badge/lts)](https://www.stackage.org/lts/package/log-effectful)+[![Stackage Nightly](https://www.stackage.org/package/log-effectful/badge/nightly)](https://www.stackage.org/nightly/package/log-effectful)++Adaptation of the [log-base](https://hackage.haskell.org/package/log-base)+library for the effectful ecosystem.++## Example++A sample usage for logging to both standard output and Elasticsearch:++```haskell+{-# LANGUAGE OverloadedStrings #-}+module Main where++import Effectful+import Effectful.Log+import Log.Backend.ElasticSearch+import Log.Backend.StandardOutput++main :: IO ()+main = runEff $ do+  let config = defaultElasticSearchConfig+        { esServer = "http://localhost:9200"+        , esIndex  = "logs"+        }+  withStdOutLogger $ \stdoutLogger -> do+    withElasticSearchLogger config $ \esLogger -> do+      runLog "main" (stdoutLogger <> esLogger) defaultLogLevel $ do+        logInfo_ "Hi there"+```
+ log-effectful.cabal view
@@ -0,0 +1,81 @@+cabal-version:      2.4+build-type:         Simple+name:               log-effectful+version:            1.0.0.0+license:            BSD-3-Clause+license-file:       LICENSE+category:           System+maintainer:         andrzej@rybczak.net+author:             Andrzej Rybczak, Dominik Peteler++synopsis:           Adaptation of the log library for the effectful ecosystem.++description:        Adaptation of the @<https://hackage.haskell.org/package/log-base log-base>@ library for the @<https://hackage.haskell.org/package/effectful effectful>@ ecosystem.++extra-source-files:+  CHANGELOG.md+  README.md++tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.4 || ==9.4.2++bug-reports: https://github.com/haskell-effectful/log-effectful/issues+source-repository head+  type:     git+  location: https://github.com/haskell-effectful/log-effectful++common language+  ghc-options:        -Wall -Wcompat -Wno-unticked-promoted-constructors++  default-language:   Haskell2010++  default-extensions: BangPatterns+                      ConstraintKinds+                      DataKinds+                      DeriveFunctor+                      DeriveGeneric+                      DerivingStrategies+                      FlexibleContexts+                      FlexibleInstances+                      GADTs+                      GeneralizedNewtypeDeriving+                      LambdaCase+                      MultiParamTypeClasses+                      NoStarIsType+                      RankNTypes+                      RoleAnnotations+                      ScopedTypeVariables+                      StandaloneDeriving+                      TupleSections+                      TypeApplications+                      TypeFamilies+                      TypeOperators++library+  import:          language++  build-depends:     base            <5+                   , effectful-core  >=1.0.0.0    && <3.0.0.0+                   , log-base        >=0.12.0.0+                   , text+                   , time++  hs-source-dirs:  src++  exposed-modules: Effectful.Log++test-suite test+  import:          language++  ghc-options:     -threaded -rtsopts -with-rtsopts=-N4++  build-depends:     base+                   , aeson+                   , effectful-core+                   , log-base+                   , log-effectful+                   , text++  hs-source-dirs: tests++  type:           exitcode-stdio-1.0+  main-is:        Main.hs
+ src/Effectful/Log.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -Wno-orphans #-}+-- | Logging via 'MonadLog'.+module Effectful.Log+  ( -- * Effect+    Log++    -- ** Handlers+  , runLog++    -- * Re-exports+  , module Log+  ) where++import Data.Text (Text)+import Data.Time.Clock+import Effectful.Dispatch.Static+import Effectful+import Log++-- | Provide the ability to log messages via 'MonadLog'.+data Log :: Effect++type instance DispatchOf Log = Static WithSideEffects+newtype instance StaticRep Log = Log LoggerEnv++-- | Run the 'Log' effect.+--+-- /Note:/ this is the @effectful@ version of 'runLogT'.+runLog+  :: IOE :> es+  => Text+  -- ^ Application component name to use.+  -> Logger+  -- ^ The logging back-end to use.+  -> LogLevel+  -- ^ The maximum log level allowed to be logged.+  -> Eff (Log : es) a+  -- ^ The computation to run.+  -> Eff es a+runLog component logger maxLogLevel = evalStaticRep $ Log LoggerEnv+  { leLogger = logger+  , leComponent = component+  , leDomain = []+  , leData = []+  , leMaxLogLevel = maxLogLevel+  }++-- | Orphan, canonical instance.+instance Log :> es => MonadLog (Eff es) where+  logMessage level message data_ = do+    time <- unsafeEff_ getCurrentTime+    Log logEnv <- getStaticRep+    unsafeEff_ $ logMessageIO logEnv time level message data_++  localData data_ = localStaticRep $ \(Log logEnv) ->+    Log logEnv { leData = data_ ++ leData logEnv }++  localDomain domain = localStaticRep $ \(Log logEnv) ->+    Log logEnv { leDomain = leDomain logEnv ++ [domain] }++  localMaxLogLevel level = localStaticRep $ \(Log logEnv) ->+    Log logEnv { leMaxLogLevel = level }++  getLoggerEnv = do+    Log env <- getStaticRep+    pure env
+ tests/Main.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE OverloadedStrings #-}+module Main where++import Effectful+import Effectful.Log+import Log.Backend.StandardOutput++main :: IO ()+main = runEff $ do+  withStdOutLogger $ \logger -> do+    runLog "main" logger defaultLogLevel app++app :: Log :> es => Eff es ()+app = localData ["local_char" .= 'x'] $ do+  logInfo "Hello!" $ object+    [ "payload" .= (123::Int)+    ]