packages feed

hlogger 0.0.2.0 → 0.0.3.0

raw patch · 6 files changed

+88/−154 lines, 6 files

Files

+ LoggerTest.hs view
@@ -0,0 +1,6 @@+import System.Log.SimpleHLogger++main = do+  logger <- simpleLogger "test"+  loggerLog logger (Just ("LoggerTest", "main")) Debug "Test"+  loggerStop logger
README view
@@ -5,7 +5,7 @@ scope of this library will be, but we will continue to evolve it in parallel with the development of Pontarius and HXMPP, utilizing it in those two projects. -We have just released HLogger 0.1 Alpha 2 with support for custom logging+We have just released HLogger 0.1 Alpha 3 with support for custom logging behaviors. See the documentation for information on how to use HLogger, and how to write your own HLogger extension. @@ -13,8 +13,6 @@  Please note that we are not recommending anyone to use HLogger at this time as it's still in an experimental stage and will have its API and data types-modified frequently. We have scheduled the first beta release for the 4th of-May. That being said, if you are interested to use HLogger anyway, feel free to-do so and to contact the Pontarius project if you need any assistance.+modified frequently. -We will release the next version, 0.1 Alpha 2, on the 13th of April.+We will release the next version, 0.1 Alpha 3, on the 4th of May.
System/Log/HLogger.hs view
@@ -6,12 +6,13 @@ --   Maintainer:  info@pontarius.org --   Stability:   unstable --   Portability: portable---   ---   This is a work in progress for a simple logging framework that aims to be+++-- | This is a work in progress for a simple logging framework that aims to be --   easy-to-use, concurrent and extendable through plug-ins. You cannot use --   this module for logging directly, instead you want to use an HLogger --   implementation. If you simply want to log messages to a file, consider---   using the SimpleLogger implementation. If you want a more complicated+--   using the @SimpleLogger@ implementation. If you want a more complicated --   logger, see below. --    --   * Implementing a Customized Logger@@ -27,75 +28,67 @@ --   See the SimpleLogger module for an example on how an implementation can be --   made. --module System.Log.HLogger (LogMessage (..), Logger (..), logger) where+module System.Log.HLogger ( ModuleName+                          , FunctionName+                          , Logger (..)+                          , LogMessage (..)+                          , LogLevel (..)+                          , logger ) where   import Control.Concurrent (forkIO) import Control.Concurrent.Chan (Chan, newChan, writeChan)+import Prelude hiding (log)  --- LogLevel indicates the importance of a log entry. The log levels are the--- same as in the Syslog application. The below list is ordered by priority,--- Debug being the least significant message.+-- | The name of the module issuing the logging instruction. -data LogLevel = Debug     | -- Debug messages-                Info      | -- Purely informational messages-                Notice    | -- Significant messages for normal conditions-                Warning   | -- Warning condition messages-                Error     | -- Error condition messages-                Critical  | -- Critical condition messages-                Alert     | -- Indication that action must be taken-                Emergency   -- Indication that the system is unusable-                deriving (Eq, Ord, Read, Show)+type ModuleName = String  +-- | The name of the function issuing the logging instruction.++type FunctionName = String++ -- | This object provides the logging API. Consult the documentation for the --   logging implementation (or SimpleLogger) about how to acquire a Logger --   object. -data Logger = Logger { -- | Logs a debug message. Debug messages are the least-                       --   significant messages.-                       logDebug :: String -> IO ()-                       -                       -- | Logs a purely informational message. Use logNotice-                       -- instead of the information message is significant.-                     , logInfo :: String -> IO ()-                       -                       -- | Logs a significant purely informational message. Use-                       --   logNotice instead of the information message is-                       --   significant.-                     , logNotice :: String -> IO ()-                       -                       -- | Logs a message signaling a warning condition.-                     , logWarning :: String -> IO ()-                       -                       -- | Logs a message signaling that a non-critical error-                       --   has occurred.-                     , logError :: String -> IO ()-                       -                       -- | Logs a message signaling that a critical error has-                       --   occurred.-                     , logCritical :: String -> IO ()-                       -                       -- | Logs a message signaling that an action must be-                       --   taken.-                     , logAlert :: String -> IO ()-                       -                       -- | Logs a message signaling that the system is-                       --   unusable.-                     , logEmergency :: String -> IO ()-                       +data Logger = Logger { -- | Logs a message.+                       loggerLog :: Maybe (ModuleName, FunctionName) ->+                                    LogLevel -> String -> IO ()+                                             -- | Stops the logger. This action is asynchronous.-                     , stopLogger :: IO () }+                     , loggerStop :: IO () }  +-- LogLevel indicates the importance of a log entry. The log levels are the+-- same as in the Syslog application. The below list is ordered by priority,+-- Debug being the least significant message.++data LogLevel = Debug     | -- ^ Debug messages are the least significant kind+                            --   of messages+                Info      | -- ^ Purely informational message; consider Notice+                            --   instead if the message is significant+                Notice    | -- ^ Significant messages for normal conditions+                Warning   | -- ^ Warning condition message+                Error     | -- ^ Error condition message+                Critical  | -- ^ Critical condition messages+                Alert     | -- ^ Indication that action must be taken+                Emergency   -- ^ Indication that the system is unusable+                deriving (Eq, Ord, Read, Show)++ -- | Used by logging implementations only. Contains information about the log --   message.  -- TODO: Add date information? -data LogMessage = LogMessage { message :: String, level :: LogLevel }+data LogMessage = LogMessage { logMessageString :: String+                             , logMessageLevel :: LogLevel+                             , logMessageContext :: Maybe (ModuleName,+                                                           FunctionName) }   -- | Used by logging implementations only. Provides a Logger object, given a@@ -106,105 +99,32 @@ logger l =   do c <- newChan      forkIO $ l c-     return Logger { logDebug = logDebug_ c-                   , logInfo = logInfo_ c-                   , logNotice = logNotice_ c-                   , logWarning = logWarning_ c-                   , logError = logError_ c-                   , logCritical = logCritical_ c-                   , logAlert = logAlert_ c-                   , logEmergency = logEmergency_ c-                   , stopLogger = stopLogger_ c }+     return Logger { loggerLog = loggerLog_ c+                   , loggerStop = loggerStop_ c }   -- Stops the logger. This action is asynchronous. -stopLogger_ :: Chan (Maybe LogMessage) -> IO ()+loggerStop_ :: Chan (Maybe LogMessage) -> IO () -stopLogger_ c = writeChan c Nothing+loggerStop_ c = writeChan c Nothing   -- Logs a debug message. Debug messages are the least significant messages. -logDebug_ :: Chan (Maybe LogMessage) -> String -> IO ()--logDebug_ c s =-  do let m = toLogMessage s Debug-     writeChan c (Just m)-     return ()----- Logs a purely informational message. Use logNotice instead of the information--- message is significant.--logInfo_ :: Chan (Maybe LogMessage) -> String -> IO ()--logInfo_ c s =-  do let m = toLogMessage s Info-     writeChan c (Just m)-     return ()----- Logs a significant purely informational message.--logNotice_ :: Chan (Maybe LogMessage) -> String -> IO ()--logNotice_ c s =-  do let m = toLogMessage s Notice-     writeChan c (Just m)-     return ()----- Logs a message signaling a warning condition.--logWarning_ :: Chan (Maybe LogMessage) -> String -> IO ()--logWarning_ c s =-  do let m = toLogMessage s Warning-     writeChan c (Just m)-     return ()----- Logs a message signaling that a non-critical error has occurred.--logError_ :: Chan (Maybe LogMessage) -> String -> IO ()--logError_ c s =-  do let m = toLogMessage s Error-     writeChan c (Just m)-     return ()----- Logs a message signaling that a critical error has occurred.--logCritical_ :: Chan (Maybe LogMessage) -> String -> IO ()--logCritical_ c s =-  do let m = toLogMessage s Critical-     writeChan c (Just m)-     return ()----- Logs a message signaling that an action must be taken.--logAlert_ c s =-  do let m = toLogMessage s Alert-     writeChan c (Just m)-     return ()----- Logs a message signaling that the system is unusable.--logEmergency_ :: Chan (Maybe LogMessage) -> String -> IO ()+loggerLog_ :: Chan (Maybe LogMessage) -> Maybe (ModuleName, FunctionName) ->+              LogLevel -> String -> IO () -logEmergency_ c s =-  do let m = toLogMessage s Emergency-     writeChan c (Just m)+loggerLog_ c x l s =+  do writeChan c $ Just (toLogMessage x l s)      return ()   -- Function to wrap a string and a log level into a LogMessage record. -toLogMessage :: String -> LogLevel -> LogMessage+toLogMessage :: Maybe (ModuleName, FunctionName) -> LogLevel -> String ->+                LogMessage -toLogMessage m l = LogMessage { message = m, level = l }+toLogMessage x l s = LogMessage { logMessageContext   = x+                                , logMessageLevel    = l+                                , logMessageString   = s }
System/Log/SimpleHLogger.hs view
@@ -6,29 +6,30 @@ --   Maintainer:  info@pontarius.org --   Stability:   unstable --   Portability: portable---   ---   This is a simple HLogger implementation that allows developers to+++-- | This is a simple HLogger implementation that allows developers to --   conveniently log to a text file. A usage example would be: --    --   @ --     import System.Log.SimpleHLogger --     main = --       do logger <- simpleLogger "LoggerTest"---          logDebug logger "This is a test message!"---          stopLogger logger+--          loggerLog logger Nothing Notice "This is a test message!"+--          loggerStop logger --   @ --    --   The above example would log "This is a test message!" to a file in the --   current directory. - -- Note that Logger is exported. This is so that applications wont have to -- import System.Log.HLogger.Logger. -module System.Log.SimpleHLogger (Logger (..), simpleLogger) where+module System.Log.SimpleHLogger (Logger (..), LogLevel (..), simpleLogger) where  -import System.Log.HLogger (LogMessage (..), Logger (..), logger)+import System.Log.HLogger (ModuleName, FunctionName, LogLevel (..),+                           LogMessage (..), Logger (..), logger) import System.IO (Handle, IOMode (WriteMode), hClose, hFlush, hPutStrLn,                   openFile) import Control.Concurrent.Chan (Chan, readChan)@@ -53,11 +54,15 @@         do logMessage <- readChan c            case logMessage of              Nothing ->-               do hClose h+               hClose h              Just m ->                do d1 <- datetime1-                  let r = d1 ++ ": " ++ show (level m) ++ ": " ++ message m-                  hPutStrLn h r+                  let context = case logMessageContext m of+                        Nothing -> ""+                        Just (x, y) -> x ++ ": " ++ y ++ ": "+                  let line = d1 ++ ": " ++ show (logMessageLevel m) ++ ": " +++                             context ++ (logMessageString m)+                  hPutStrLn h line                   hFlush h                   loggerLoop h c 
hlogger.cabal view
@@ -2,7 +2,7 @@ -- TODO: Highlighting bug: The last line of the description.  Name:               hlogger-Version:            0.0.2.0+Version:            0.0.3.0 Cabal-Version:      >= 1.6 Build-Type:         Simple License:            BSD3@@ -59,5 +59,5 @@   Type:     darcs   -- Module:   Location: https://patch-tag.com/r/jonkri/hlogger-  Tag:      0.0.2.0+  Tag:      0.0.3.0   -- Subdir:
+ install.sh view
@@ -0,0 +1,5 @@+#!/bin/sh+runhaskell Setup.hs configure --user+runhaskell Setup.hs build+runhaskell Setup.hs install+