-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A python logging style log library -- -- Please see the http://hackage.haskell.org/package/log4hs @package log4hs @version 0.2.0.0 module Logging.Utils addZonedTime :: NominalDiffTime -> ZonedTime -> ZonedTime diffZonedTime :: ZonedTime -> ZonedTime -> NominalDiffTime zonedTimeToPOSIXSeconds :: ZonedTime -> NominalDiffTime timestamp :: NominalDiffTime -> Double seconds :: NominalDiffTime -> Integer milliseconds :: NominalDiffTime -> Integer microseconds :: NominalDiffTime -> Integer openLogFile :: FilePath -> TextEncoding -> IO Handle rotateFile :: FilePath -> FilePath -> IO () modifyBaseName :: FilePath -> (String -> String) -> FilePath module Logging.Types -- | Logger is just a name. type Logger = String -- | Level also known as severity, a higher Level means a -- bigger Int. -- -- There are 5 common severity levels: -- -- -- --
--   >>> :set -XOverloadedStrings
--   
--   >>> "DEBUG" :: Level
--   DEBUG
--   
--   >>> "DEBUG" == (Level 10)
--   True
--   
newtype Level Level :: Int -> Level -- | Filters are used to perform arbitrary filtering of -- LogRecords. -- -- Sinks and Handlers can optionally use Filter -- to filter records as desired. It allows events which are below a -- certain point in the sink hierarchy. For example, a filter initialized -- with A.B will allow events logged by loggers A.B, -- A.B.C, A.B.C.D, A.B.D etc. but not A.BB, -- B.A.B etc. If initialized name with the empty string, all -- events are passed. newtype Filter Filter :: Logger -> Filter -- | List of Filter type Filterer = [Filter] -- | A LogRecord represents an event being logged. -- -- LogRecords are created every time something is logged. They -- contain all the information related to the event being logged. -- -- It includes the main message as well as information such as when the -- record was created, the source line where the logging call was made. -- -- LogRecord can be formatted into string by Format from -- vformat package, see format1 for more information. -- -- Currently, the useful attributes in a LogRecord are described by: -- --
--   logger        name of the logger, see Logger
--   level         logging level for the message, see Level
--   message       the main message passed to logv debug info ..
--   pathname      full pathname of the source file where the logging call was issued (if available)
--   filename      filename portion of pathname
--   pkgname       package name where the logging call was issued (if available)
--   modulename    module name (e.g. Main, Logging.Types)
--   lineno        source line number where the logging call was issued (if available)
--   asctime       ZonedTime when the LogRecord was created
--   utctime       UTCTime when the LogRecord was created
--   created       timestamp when the LogRecord was created
--   msecs         millisecond portion of the creation time
--   
-- -- Format examples: -- --
--   "{message}"
--   "{logger} {level}: {message}"
--   "{logger:<20.20s} {level:<8s}: {message}"
--   "{asctime:%Y-%m-%dT%H:%M:%S%6Q%z} - {level} - {logger}] {message}"
--   
data LogRecord LogRecord :: Logger -> Level -> String -> String -> String -> String -> String -> Int -> ZonedTime -> UTCTime -> Double -> Integer -> LogRecord [$sel:logger:LogRecord] :: LogRecord -> Logger [$sel:level:LogRecord] :: LogRecord -> Level [$sel:message:LogRecord] :: LogRecord -> String [$sel:pathname:LogRecord] :: LogRecord -> String [$sel:filename:LogRecord] :: LogRecord -> String [$sel:pkgname:LogRecord] :: LogRecord -> String [$sel:modulename:LogRecord] :: LogRecord -> String [$sel:lineno:LogRecord] :: LogRecord -> Int [$sel:asctime:LogRecord] :: LogRecord -> ZonedTime [$sel:utctime:LogRecord] :: LogRecord -> UTCTime [$sel:created:LogRecord] :: LogRecord -> Double [$sel:msecs:LogRecord] :: LogRecord -> Integer -- | A handler type which writes logging records, appropriately formatted, -- to a stream. data StreamHandler StreamHandler :: Level -> Filterer -> Format1 -> Handle -> StreamHandler [$sel:level:StreamHandler] :: StreamHandler -> Level [$sel:filterer:StreamHandler] :: StreamHandler -> Filterer [$sel:formatter:StreamHandler] :: StreamHandler -> Format1 [$sel:stream:StreamHandler] :: StreamHandler -> Handle -- | A handler type which writes logging records, appropriately formatted, -- to a file. data FileHandler FileHandler :: Level -> Filterer -> Format1 -> FilePath -> TextEncoding -> IORef Handle -> FileHandler [$sel:level:FileHandler] :: FileHandler -> Level [$sel:filterer:FileHandler] :: FileHandler -> Filterer [$sel:formatter:FileHandler] :: FileHandler -> Format1 [$sel:file:FileHandler] :: FileHandler -> FilePath [$sel:encoding:FileHandler] :: FileHandler -> TextEncoding [$sel:stream:FileHandler] :: FileHandler -> IORef Handle -- | Sink represents a single logging channel. -- -- A "logging channel" indicates an area of an application. Exactly how -- an "area" is defined is up to the application developer. Since an -- application can have any number of areas, logging channels are -- identified by a unique string. Application areas can be nested (e.g. -- an area of "input processing" might include sub-areas "read CSV -- files", "read XLS files" and "read Gnumeric files"). To cater for this -- natural nesting, channel names are organized into a namespace -- hierarchy where levels are separated by periods, much like the Haskell -- module namespace. So in the instance given above, channel names might -- be Input for the upper level, and Input.Csv, -- Input.Xls and Input.Gnu for the sub-levels. There is no -- arbitrary limit to the depth of nesting. -- -- Note: The namespaces are case sensitive. data Sink Sink :: Logger -> Level -> Filterer -> [SomeHandler] -> Bool -> Bool -> Sink [$sel:logger:Sink] :: Sink -> Logger [$sel:level:Sink] :: Sink -> Level [$sel:filterer:Sink] :: Sink -> Filterer [$sel:handlers:Sink] :: Sink -> [SomeHandler] [$sel:disabled:Sink] :: Sink -> Bool -- | It will pop up until root or the ancestor's propagation is disabled [$sel:propagate:Sink] :: Sink -> Bool -- | There is under normal circumstances just one Manager, which -- holds the hierarchy of sinks. data Manager Manager :: Sink -> Map String Sink -> Bool -> Bool -> Manager [root] :: Manager -> Sink [sinks] :: Manager -> Map String Sink [disabled] :: Manager -> Bool [catchUncaughtException] :: Manager -> Bool -- | A class represents a common trait of filtering LogRecords class Filterable a filter :: Filterable a => a -> LogRecord -> Bool -- | The SomeHandler type is the root of the handler type hierarchy. -- It holds the real Handler instance data SomeHandler [SomeHandler] :: Handler h => h -> SomeHandler -- | A type class that abstracts the characteristics of a Handler -- -- Note: Locking is not necessary, because Handle has done it on -- handle operations. class (HasType Level a, HasType Filterer a, HasType Format1 a, Typeable a, Eq a) => Handler a open :: Handler a => a -> IO () emit :: Handler a => a -> LogRecord -> IO () close :: Handler a => a -> IO () handle :: Handler a => a -> LogRecord -> IO Bool fromHandler :: Handler a => SomeHandler -> Maybe a toHandler :: Handler a => a -> SomeHandler module Logging.Aeson instance Data.Aeson.Types.FromJSON.FromJSON (GHC.Types.IO Logging.Types.Manager.Manager) instance Data.Aeson.Types.FromJSON.FromJSON Logging.Types.Level.Level instance Data.Aeson.Types.FromJSON.FromJSON Logging.Types.Filter.Filter instance Data.Aeson.Types.FromJSON.FromJSON Text.Format.Format.Format1 instance Data.Aeson.Types.FromJSON.FromJSON Logging.Types.Handlers.StreamHandler.StreamHandler instance Data.Aeson.Types.FromJSON.FromJSON (GHC.Types.IO Logging.Types.Handlers.FileHandler.FileHandler) instance Data.Aeson.Types.FromJSON.FromJSON (GHC.Types.IO Logging.Types.Class.Handler.SomeHandler) instance Data.Aeson.Types.FromJSON.FromJSON (Data.Map.Internal.Map GHC.Base.String Text.Format.Format.Format1 -> GHC.Types.IO Logging.Types.Class.Handler.SomeHandler) instance Data.Aeson.Types.FromJSON.FromJSON Logging.Types.Sink.Sink instance Data.Aeson.Types.FromJSON.FromJSON (GHC.Base.String -> Data.Map.Internal.Map GHC.Base.String Logging.Types.Class.Handler.SomeHandler -> Logging.Types.Sink.Sink) -- |

A python logging style log library.

-- --

A simple example:

-- --
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE TemplateHaskell   #-}
--   
--   module Main ( main ) where
--   
--   import           Data.Aeson
--   import           Data.Maybe
--   import           Logging
--   import           Prelude    hiding (error)
--   
--   main :: IO ()
--   main = fromJust (decode "{}") >>= flip run app
--   
--   myLogger = "MyLogger.Main"
--   
--   app :: IO ()
--   app = do
--     $(debug) myLogger "this is a test message"
--     $(info) myLogger "this is a test message"
--     $(warn) myLogger "this is a test message"
--     $(error) myLogger "this is a test message"
--     $(fatal) myLogger "this is a test message"
--     $(logv) myLogger "LEVEL 100" "this is a test message"
--   
-- -- See Logging.Aeson to lean more about decoding json into -- Manager module Logging -- | Run a logging environment from JSON Value. -- -- A combinator of run and fromJSON -- -- A combinator of jsonToManager and run -- -- See Aeson -- | Deprecated: will be removed in 1.0.0 runJson :: Value -> IO a -> IO a -- | Make a Manager from JSON Value -- -- Decode Value into Manager -- -- See Aeson -- | Deprecated: will be removed in 1.0.0 jsonToManager :: Value -> IO Manager -- | Run a logging environment. -- -- You should always write you application inside a logging environment. -- --
    --
  1. rename "main" function to "originMain" (or whatever you call -- it)
  2. --
  3. write "main" as below
  4. --
-- --
--   main :: IO ()
--   main = run manager originMain
--   ...
--   
run :: Manager -> IO a -> IO a -- | A StreamHandler bound to stderr stderrHandler :: StreamHandler -- | A StreamHandler bound to stdout stdoutHandler :: StreamHandler -- | Default root sink which is used by jsonToManager when -- root is missed. -- -- You can use it when you make Manager manually. defaultRoot :: Sink -- | Log "message" with the severity "level". -- -- The missing type signature: MonadIO m => Logger -> -- Level -> String -> m () logv :: ExpQ -- | Log "message" with a specific severity. -- -- The missing type signature: MonadIO m => Logger -> -- String -> m () debug :: ExpQ -- | Log "message" with a specific severity. -- -- The missing type signature: MonadIO m => Logger -> -- String -> m () info :: ExpQ -- | Log "message" with a specific severity. -- -- The missing type signature: MonadIO m => Logger -> -- String -> m () warn :: ExpQ -- | Log "message" with a specific severity. -- -- The missing type signature: MonadIO m => Logger -> -- String -> m () error :: ExpQ -- | Log "message" with a specific severity. -- -- The missing type signature: MonadIO m => Logger -> -- String -> m () fatal :: ExpQ