packages feed

micrologger (empty) → 0.2.0.1

raw patch · 4 files changed

+154/−0 lines, 4 filesdep +basedep +textdep +text-formatsetup-changed

Dependencies added: base, text, text-format, time, transformers

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Savanni D'Gerinel (c) 2016++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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ micrologger.cabal view
@@ -0,0 +1,45 @@+name:                micrologger+version:             0.2.0.1+synopsis:            A super simple logging module. Only for use for very simple projects.+description:         A super simple logging module. Only for use for very simple projects.+homepage:            https://github.com/savannidgerinel/micrologger#readme+license:             BSD3+license-file:        LICENSE+author:              Savanni D'Gerinel+maintainer:          savanni@savannidgerinel.com+copyright:           2016 Savanni D'Gerinel+category:            Web+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:       src+  default-language:     Haskell2010+  ghc-options:          -Wall++  exposed-modules:      LuminescentDreams.Logger++  build-depends:          base          >= 4.7  && < 5+                        , text          >= 1.2  && < 1.3+                        , text-format   >= 0.3  && < 0.4+                        , time          >= 1.5  && < 1.6+                        , transformers  >= 0.4  && < 0.5++-- test-suite micrologger-test+--   type:               exitcode-stdio-1.0+--   hs-source-dirs:     test+--   ghc-options:        -threaded -rtsopts -with-rtsopts=-N+--   default-language:   Haskell2010+--   main-is:            Spec.hs+--+--   other-modules:      LogSpec+--+--   build-depends:        base+--                       , micrologger+--                       , hspec+--                       , text++source-repository head+  type:     git+  location: https://github.com/savannidgerinel/micrologger
+ src/LuminescentDreams/Logger.hs view
@@ -0,0 +1,77 @@+{-# LANGUAGE DeriveFunctor          #-}+{-# LANGUAGE FlexibleInstances      #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses  #-}+{-# LANGUAGE OverloadedStrings      #-}+{-# LANGUAGE RecordWildCards        #-}+{-# OPTIONS_GHC -fno-warn-orphans   #-}+module LuminescentDreams.Logger (+    LogLevel(..), Logger(..), LogMsg, formatMsg, logMsg+  )+  where++-- import           Control.Monad.IO.Class   (MonadIO, liftIO)+import           Data.Monoid+import qualified Data.Text.Format         as TF+import qualified Data.Text.Lazy           as T+import qualified Data.Text.Buildable      as TFB+import qualified Data.Time                as Time+import qualified Data.List                as List+++{-+A writer monad running over a LogMsg. It can write to a variety of things. That has to be part of the structure. Pattern:++msg -> writer -> writer++writer -> writer is a data structure, specifically WriterM.+-}+--+-- class (Monoid w, Monad m) => MonadLogger w m where+--   logMsg :: LogMsg -> w -> m a+--+--+data LogLevel = LogDebug+              | LogInfo+              | LogWarning+              | LogError+              | LogEmergency+              deriving (Eq, Ord)++data Logger = Logger (T.Text -> IO ()) LogLevel++data LogMsg = LogMsg LogLevel [(String, String)] String++logMsg :: Logger -> LogLevel -> [(String, String)] -> String -> IO ()+logMsg l lvl tags text = logMsg_ l (LogMsg lvl tags text)++logMsg_ :: Logger -> LogMsg -> IO ()+logMsg_ (Logger writer pri) msg@(LogMsg lvl _ _) =+  if lvl >= pri+    then do+      t <-  Time.getCurrentTime+      writer $ formatMsg t msg+    else return ()+++formatMsg :: Time.UTCTime -> LogMsg -> T.Text+formatMsg t (LogMsg lvl tags text) =+  TF.format "{} {} {} {}" (Time.formatTime Time.defaultTimeLocale "%Y-%m-%d %H:%M:%S" t, lvl, tags, text)+++instance TFB.Buildable LogLevel where+  build LogDebug      = TFB.build ("DEBUG" :: String)+  build LogInfo       = TFB.build ("INFO" :: String)+  build LogWarning    = TFB.build ("WARNING" :: String)+  build LogError      = TFB.build ("ERROR" :: String)+  build LogEmergency  = TFB.build ("EMERGENCY" :: String)++instance TFB.Buildable (String, String) where+  build (name, value) = TFB.build $ "(" <> name <> ", " <> value <> ")"++instance TFB.Buildable [(String, String)] where+  -- build lst = TFB.build "[" <> TFB.build `fmap` lst "]"+  build lst =+    mconcat $ [TFB.build ("[" :: String)]+           <>  (List.intersperse (TFB.build (", " :: String)) (TFB.build `fmap` lst))+           <> [TFB.build ("]" :: String)]