little-logger (empty) → 0.1.0
raw patch · 5 files changed
+160/−0 lines, 5 filesdep +basedep +co-logdep +co-log-coresetup-changed
Dependencies added: base, co-log, co-log-core, microlens, mtl, text
Files
- LICENSE +30/−0
- README.md +5/−0
- Setup.hs +2/−0
- little-logger.cabal +44/−0
- src/LittleLogger.hs +79/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2020++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 Author name here 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,5 @@+# little-logger++[](https://circleci.com/gh/ejconlon/little-logger/tree/master)++Basic logging based on co-log. The difference is that our log action runs in IO, and we expect to use it in any IO-lifting monad.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ little-logger.cabal view
@@ -0,0 +1,44 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.33.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: 116369e1748442fb579db3e98e1e84bd8587dfe04d6f401f9cd571b200220673++name: little-logger+version: 0.1.0+synopsis: Basic logging based on co-log+description: Please see the README on GitHub at <https://github.com/ejconlon/little-logger#readme>+category: Logging+homepage: https://github.com/ejconlon/little-logger#readme+bug-reports: https://github.com/ejconlon/little-logger/issues+author: Eric Conlon+maintainer: ejconlon@gmail.com+copyright: (c) 2020 Eric Conlon+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md++source-repository head+ type: git+ location: https://github.com/ejconlon/little-logger++library+ exposed-modules:+ LittleLogger+ other-modules:+ Paths_little_logger+ hs-source-dirs:+ src+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -fno-warn-unused-top-binds+ build-depends:+ base >=4.12 && <5+ , co-log >=0.4+ , co-log-core >=0.2+ , microlens >=0.4+ , mtl >=2.2+ , text >=1.2+ default-language: Haskell2010
+ src/LittleLogger.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE ConstraintKinds #-}++{-| Basic logging based on co-log. The difference is that our log action runs in IO, and+ we expect to use it in any IO-lifting monad. -}+module LittleLogger+ ( LogApp (..)+ , SimpleLogAction+ , HasSimpleLog (..)+ , WithSimpleLog+ , logAppLogAction+ , defaultSimpleLogAction+ , logMsg+ , logDebug+ , logError+ , logException+ , logInfo+ , logWarning+ , logWithSeverity+ , newLogApp+ ) where++import Colog.Actions (richMessageAction)+import Colog.Core.Action (LogAction (..))+import Colog.Core.Severity (Severity (..))+import Colog.Message (Message, Msg (..))+import Control.Exception (Exception, displayException)+import Control.Monad.IO.Class (MonadIO (..))+import Control.Monad.Reader (MonadReader (..))+import Data.Text (Text)+import qualified Data.Text as Text+import GHC.Stack (HasCallStack, callStack, withFrozenCallStack)+import Lens.Micro (Lens', lens)+import Lens.Micro.Extras (view)+import Prelude++type SimpleLogAction = LogAction IO Message++class HasSimpleLog env where+ simpleLogL :: Lens' env SimpleLogAction++type WithSimpleLog env m = (MonadIO m, MonadReader env m, HasSimpleLog env, HasCallStack)++defaultSimpleLogAction :: SimpleLogAction+defaultSimpleLogAction = richMessageAction++logMsg :: WithSimpleLog env m => Message -> m ()+logMsg msg = do+ env <- ask+ let LogAction act = view simpleLogL env+ liftIO (act msg)++logWithSeverity :: WithSimpleLog env m => Severity -> Text -> m ()+logWithSeverity sev txt = withFrozenCallStack (logMsg Msg { msgStack = callStack, msgSeverity = sev, msgText = txt })++logDebug :: WithSimpleLog env m => Text -> m ()+logDebug = withFrozenCallStack (logWithSeverity Debug)++logInfo :: WithSimpleLog env m => Text -> m ()+logInfo = withFrozenCallStack (logWithSeverity Info)++logWarning :: WithSimpleLog env m => Text -> m ()+logWarning = withFrozenCallStack (logWithSeverity Warning)++logError :: WithSimpleLog env m => Text -> m ()+logError = withFrozenCallStack (logWithSeverity Error)++logException :: (WithSimpleLog env m, Exception e) => e -> m ()+logException = withFrozenCallStack (logError . Text.pack . displayException)++newtype LogApp = LogApp { _logAppLogAction :: SimpleLogAction }++logAppLogAction :: Lens' LogApp SimpleLogAction+logAppLogAction = lens _logAppLogAction (const LogApp)++instance HasSimpleLog LogApp where+ simpleLogL = logAppLogAction++newLogApp :: LogApp+newLogApp = LogApp defaultSimpleLogAction