simple-log 0.1.2 → 0.1.3
raw patch · 8 files changed
+49/−22 lines, 8 filesdep +filepath
Dependencies added: filepath
Files
- LICENSE +30/−0
- simple-log.cabal +5/−1
- src/System/Log/Base.hs +7/−10
- src/System/Log/Config.hs +4/−8
- src/System/Log/Console.hs +0/−1
- src/System/Log/File.hs +2/−1
- src/System/Log/Monad.hs +0/−1
- src/System/Log/Text.hs +1/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Alexandr `Voidex` Ruchkin + +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 Alexandr `Voidex` Ruchkin 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.
simple-log.cabal view
@@ -1,8 +1,9 @@ Name: simple-log -Version: 0.1.2 +Version: 0.1.3 Synopsis: Simple log for Haskell Description: Log library for Haskell with removing unnecessary traces License: BSD3 +License-file: LICENSE Author: Alexandr `Voidex` Ruchkin Homepage: http://github.com/mvoidex/simple-log Maintainer: voidex@live.com @@ -19,6 +20,7 @@ time >= 1.3 && < 1.5, text >= 0.11 && < 0.12, old-locale >= 1.0 && < 1.1, + filepath >= 1.0 && < 1.4, directory >= 1.1 && < 1.3, transformers >= 0.2 && < 0.4, MonadCatchIO-transformers >= 0.2 && < 0.4, @@ -32,3 +34,5 @@ System.Log.HTML System.Log.Console System.Log.File + + Ghc-Options: -Wall
src/System/Log/Base.hs view
@@ -23,15 +23,12 @@ import Prelude hiding (log) -import Control.Applicative import Control.Arrow import qualified Control.Exception as E import Control.Concurrent -import Control.Concurrent.Chan import Control.DeepSeq import Control.Monad import Data.List -import qualified Data.Map as M import Data.Text (Text) import qualified Data.Text as T import Data.Time @@ -76,15 +73,15 @@ -- | Absolute scope-path absolute :: [Text] -> [Text] -> Bool -absolute path = (== path) +absolute p = (== p) -- | Relative scope-path relative :: [Text] -> [Text] -> Bool -relative path = (path `isSuffixOf`) +relative p = (p `isSuffixOf`) -- | Scope-path for child child :: ([Text] -> Bool) -> [Text] -> Bool -child r [] = False +child _ [] = False child r (_:ps) = r ps -- | Root scope-path @@ -232,7 +229,7 @@ Scope Text Rules [Entry] foldEntry :: (Message -> a) -> (Text -> Rules -> [a] -> a) -> Entry -> a -foldEntry r s (Entry m) = r m +foldEntry r _ (Entry m) = r m foldEntry r s (Scope t rs es) = s t rs (map (foldEntry r s) es) -- | Command to logger @@ -273,11 +270,11 @@ isNotTrace = onLevel True (>= politicsLow ps) onLevel :: a -> (Level -> a) -> Entry -> a - onLevel v f (Scope _ _ _) = v - onLevel v f (Entry (Message _ l _ _)) = f l + onLevel v _ (Scope _ _ _) = v + onLevel _ f (Entry (Message _ l _ _)) = f l -- | Apply rules to path apply :: Rules -> [Text] -> Politics -> Politics -apply rs path = foldr (.) id . map applier . reverse . inits $ path where +apply rs = foldr (.) id . map applier . reverse . inits where applier :: [Text] -> Politics -> Politics applier spath = foldr (.) id . map rulePolitics . filter (`rulePath` spath) $ rs
src/System/Log/Config.hs view
@@ -19,10 +19,6 @@ import System.Log.Base -instance Error Text where - noMsg = strMsg noMsg - strMsg = T.pack - -- | Parse rule -- -- Format: @@ -56,7 +52,7 @@ where (p, r) = T.break (== ':') txt parseUses uses = do - tell fails + tell $ map T.pack fails return $ foldr (.) id oks where (fails, oks) = (lefts &&& rights) . map (parseUse . T.strip) . T.split (== ',') $ uses @@ -66,13 +62,13 @@ ["high", v] -> high <$> value v ["set", l, h] -> politics <$> value l <*> value h ["use", v] -> use <$> predefined v - _ -> throwError $ T.concat ["Unable to parse: ", u] + _ -> throwError $ concat ["Unable to parse: ", T.unpack u] value v = maybe noValue return $ lookup v values where - noValue = throwError $ T.concat ["Invalid value: ", v] + noValue = throwError $ concat ["Invalid value: ", T.unpack v] predefined v = maybe noPredefined return $ lookup v predefineds where - noPredefined = throwError $ T.concat ["Invalid predefined: ", v] + noPredefined = throwError $ concat ["Invalid predefined: ", T.unpack v] parseRules :: Text -> Writer [Text] Rules parseRules = mapM parseRule . filter (not . T.null . T.strip) . T.lines
src/System/Log/Console.hs view
@@ -3,7 +3,6 @@ ) where import Data.Text (Text) -import qualified Data.Text as T import qualified Data.Text.IO as T import System.Log.Base
src/System/Log/File.hs view
@@ -3,14 +3,15 @@ ) where import Data.Text (Text) -import qualified Data.Text as T import qualified Data.Text.IO as T import System.Log.Base +import System.FilePath import System.Directory import System.IO file :: FilePath -> IO (Consumer Text) file f = do + createDirectoryIfMissing True $ takeDirectory f ex <- doesFileExist f let putText txt = withFile f AppendMode $ \h -> T.hPutStrLn h txt
src/System/Log/Monad.hs view
@@ -6,7 +6,6 @@ import Prelude hiding (log, catch) -import Control.Concurrent.Chan import Control.Exception (SomeException) import Control.Monad.IO.Class import Control.Monad.Reader
src/System/Log/Text.hs view
@@ -10,6 +10,7 @@ import System.Log.Base -- | Default time format +defaultTimeFormat :: String defaultTimeFormat = "%d/%m/%y %T %z" -- | Text log converter with time format