heavy-log-shortcuts (empty) → 1.0.0
raw patch · 5 files changed
+219/−0 lines, 5 filesdep +basedep +fast-loggerdep +heavy-loggersetup-changed
Dependencies added: base, fast-logger, heavy-logger, monad-control, text, text-format-heavy
Files
- LICENSE +21/−0
- Readme.md +37/−0
- Setup.hs +2/−0
- heavy-log-shortcuts.cabal +45/−0
- src/System/Log/Heavy/Short.hs +114/−0
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2019 Jappie Klooster++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,37 @@+# Heavy log shortcuts++An alternative shortcut api for heavy-logger.+This has infected several of my projects already so I'm+putting it online.+Although, it maybe better to use someting like [katip](http://hackage.haskell.org/package/katip)+I just don't want to invest the time into learning another logging framework.++Removes the vars functionality, fixes not being able to use '{}'.+Puts in place some sane default shortcuts.++If we don't want data use:++```haskell+debug0 "msg"+```++if we do want data (which is almost always the case):++```haskell+debug "msg" somedata+```++If we want multiple datas:++```haskell+debug "msg" (onedata, twodata)+```++I usually import this module qualified as Log,+then you can do:++```haskell+Log.debug "oh no my house is on fire" house+```++Now it reads almost like a sentence.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ heavy-log-shortcuts.cabal view
@@ -0,0 +1,45 @@+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 3b981391273a612ef21c6a06b2d58308ad147ebf75c032180f8f11df9ec51bb8++name: heavy-log-shortcuts+version: 1.0.0+synopsis: Simle api for heavy logger+description: An alternative shortcut api for heavy-logger, removes vars functionality.+category: System+homepage: https://github.com/jappeace/template#readme+bug-reports: https://github.com/jappeace/template/issues+author: Jappie Klooster+maintainer: jappieklooster@hotmail.com+copyright: 2019 Jappie Klooster+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10+extra-source-files:+ LICENSE+ Readme.md++source-repository head+ type: git+ location: https://github.com/jappeace/template++library+ exposed-modules:+ System.Log.Heavy.Short+ other-modules:+ Paths_heavy_log_shortcuts+ hs-source-dirs:+ src+ default-extensions: EmptyCase FlexibleContexts FlexibleInstances InstanceSigs MultiParamTypeClasses LambdaCase MultiWayIf NamedFieldPuns TupleSections DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies GeneralizedNewtypeDeriving StandaloneDeriving OverloadedStrings TypeApplications+ ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wredundant-constraints -Wincomplete-record-updates -Widentities+ build-depends:+ base >=4.7 && <5+ , fast-logger+ , heavy-logger >=0.3.1.0 && <0.4+ , monad-control+ , text+ , text-format-heavy+ default-language: Haskell2010
+ src/System/Log/Heavy/Short.hs view
@@ -0,0 +1,114 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE RankNTypes #-}++-- | Wraps the monad logger library+-- Bunch of aliases for heavy logger, simpler api+module System.Log.Heavy.Short+ ( run+ , discard+ , info+ , debug+ , warn+ , error+ , info0+ , debug0+ , warn0+ , error0+ , dump+ , lift+ ) where++import Control.Monad.IO.Class+import Control.Monad.Trans.Control+import Data.Monoid ((<>))+import qualified Data.Text as Text+import Data.Text.Format.Heavy.Instances (Single (..))+import qualified Data.Text.Lazy as Lazy+import Prelude (Char, IO, ($))+import System.Log.FastLogger as FL+import System.Log.Heavy+import System.Log.Heavy.Format+import System.Log.Heavy.LoggingT (LoggingT)+import qualified System.Log.Heavy.Shortcuts as Logcut (debug, info,+ reportError,+ warning)+import System.Log.Heavy.Types (LoggingSettings (..))++import Text.Show (Show, show)++-- | Bigger buffer size than default+stdoutSettings :: LogBackendSettings FastLoggerBackend+stdoutSettings = FastLoggerSettings defaultLogFormat (FL.LogStdout 500000)++-- | Run the logger with default settings+run :: (MonadBaseControl IO m, MonadIO m) => LoggingT m a -> m a+run = withLoggingT $ LoggingSettings stdoutSettings++-- | Throw away the logs.+-- While running tests we often don't care about log output.+discard :: (MonadBaseControl IO m, MonadIO m) => LoggingT m a -> m a+discard = withLoggingT $ LoggingSettings NullLogSettings++source :: Text.Text+source = "Log"++showT :: Show a => a -> Text.Text+showT v = Text.pack $ show v++dump ::+ forall m a. (MonadIO m, HasLogging m, Show a)+ => a+ -> m ()+dump d = debug0 $ showT d++-- | Log func with a variable+type VarLog+ = forall m a. (MonadIO m, HasLogging m, Show a) =>+ Text.Text -> a -> m ()++-- | Log func that just accepts text+type SimpleLog+ = forall m. (MonadIO m, HasLogging m) =>+ Text.Text -> m ()++info :: VarLog+info d b = info0 $ d <> showT b++info0 :: SimpleLog+info0 = monkeyPatch Logcut.info++debug :: VarLog+debug d b = debug0 $ d <> showT b++debug0 :: SimpleLog+debug0 = monkeyPatch Logcut.debug++warn :: VarLog+warn d b = warn0 $ d <> showT b++warn0 :: SimpleLog+warn0 = monkeyPatch Logcut.warning++error :: VarLog+error d b = error0 $ d <> showT b++error0 :: SimpleLog+error0 = monkeyPatch Logcut.reportError++-- | Heavy logger will eat { and }, we replace them with < and >+monkeyPatch ::+ (Lazy.Text -> Single Text.Text -> m ())+ -> Text.Text+ -> m ()+monkeyPatch func d = func (Lazy.fromStrict (Text.map format d)) (Single source)++-- | heavy logger doesn't like '{'+format :: Char -> Char+format '{' = '<'+format '}' = '>'+format x = x+++lift :: MonadIO m => LoggingT IO a -> LoggingT m a+lift ioM =+ liftWith $ \runner -> liftIO $ runner $ ioM