-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A python logging style log library -- -- Please see the README @package log4hs @version 0.0.2.0 -- |

A python logging style log library.

-- --

A full example:

-- --
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE QuasiQuotes       #-}
--   {-# LANGUAGE RecordWildCards   #-}
--   {-# LANGUAGE TemplateHaskell   #-}
--   
--   
--   module Main (main) where
--   
--   import           Data.Aeson.QQ.Simple (aesonQQ)
--   import           Prelude hiding (error)
--   import           Logging (runJson, debug, info, warn, error, fatal, logv)
--   
--   main :: IO ()
--   main = runJson manager app
--   
--   myLogger = "MyLogger.Main"
--   
--   app :: IO ()
--   app = do
--     $(debug) myLogger "this message should print into MyLogger"
--     $(info) myLogger "this message should print into MyLogger"
--     $(warn) myLogger "this message should print into MyLogger"
--     $(error) myLogger "this message should print into MyLogger"
--     $(fatal) myLogger "this message should print into MyLogger"
--     $(logv) myLogger "LEVEL 100" "this message should print into MyLogger"
--   
--   -- The best practice is putting all config into a separate file,
--   -- e.g "Logging.json"
--   manager = [aesonQQ|{
--     "loggers": {
--       "root": {
--         "level": "DEBUG",
--         "handlers": ["console"],
--         "propagate": false
--       },
--       "MyLogger": {
--         "level": "INFO",
--         "filterer": ["MyLogger.Main"],
--         "handlers": ["file"],
--         "propagate": false
--       }
--     },
--     "handlers": {
--       "console": {
--         "type": "StreamHandler",
--         "stream": "stderr",
--         "level": "DEBUG",
--         "formatter": "defaultFormatter"
--       },
--       "file": {
--         "type": "FileHandler",
--         "level": "INFO",
--         "formatter": "defaultFormatter",
--         "file": "./default.log"
--       }
--     },
--     "formatters": {
--       "defaultFormatter": {
--         "fmt": "%(asctime)s - %(level)s - %(logger)s - %(pathname)s/%(filename)s:%(lineno)d] %(message)s"
--       }
--     }
--   }|]
--   
module Logging -- | 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 -- | Run a logging environment from JSON Value. -- -- A combinator of run and jsonToManager. runJson :: Value -> IO a -> IO a -- | Make a Manager from JSON Value. jsonToManager :: Value -> IO Manager -- | 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 -- | A type class that abstracts the characteristics of a Handler class Handler a getLevel :: Handler a => a -> Level setLevel :: Handler a => a -> Level -> a getFilterer :: Handler a => a -> Filterer setFilterer :: Handler a => a -> Filterer -> a getFormatter :: Handler a => a -> Formatter setFormatter :: Handler a => a -> Formatter -> a acquire :: Handler a => a -> IO () release :: Handler a => a -> IO () with :: Handler a => a -> (a -> IO b) -> IO b emit :: Handler a => a -> LogRecord -> IO () flush :: Handler a => a -> IO () close :: Handler a => a -> IO () handle :: Handler a => a -> LogRecord -> IO 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 [$sel:root:Manager] :: Manager -> Sink [$sel:sinks:Manager] :: Manager -> Map String Sink [$sel:disabled:Manager] :: Manager -> Bool [$sel:catchUncaughtException:Manager] :: Manager -> Bool -- | 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 -> [HandlerT] -> Bool -> Bool -> Sink [$sel:logger:Sink] :: Sink -> Logger [$sel:level:Sink] :: Sink -> Level [$sel:filterer:Sink] :: Sink -> Filterer [$sel:handlers:Sink] :: Sink -> [HandlerT] [$sel:disabled:Sink] :: Sink -> Bool [$sel:propagate:Sink] :: Sink -> Bool -- | A GADT represents any Handler instance data HandlerT [HandlerT] :: Handler a => a -> HandlerT -- | A handler type which writes logging records, appropriately formatted, -- to a stream. -- -- Note that this class does not close the stream when the stream is a -- terminal device, e.g. stderr and stdout. data StreamHandler StreamHandler :: Handle -> Level -> Filterer -> Formatter -> MVar () -> StreamHandler [$sel:stream:StreamHandler] :: StreamHandler -> Handle [$sel:level:StreamHandler] :: StreamHandler -> Level [$sel:filterer:StreamHandler] :: StreamHandler -> Filterer [$sel:formatter:StreamHandler] :: StreamHandler -> Formatter [$sel:lock:StreamHandler] :: StreamHandler -> MVar () -- | Formatters are used to convert a LogRecord to text. -- -- Formatters need to know how a LogRecord is constructed. -- They are responsible for converting a LogRecord to (usually) a -- string which can be interpreted by either a human or an external -- system. The base Formatter allows a formatting string to be -- specified. If none is supplied, the default value, "%(message)s" is -- used. -- -- The Formatter can be initialized with a format string which -- makes use of knowledge of the LogRecord attributes - e.g. the -- default value mentioned above makes use of a LogRecord's -- message attribute. Currently, the useful attributes in a -- LogRecord are described by: -- -- data Formatter Formatter :: String -> String -> Formatter [$sel:fmt:Formatter] :: Formatter -> String [$sel:datefmt:Formatter] :: Formatter -> String -- | List of Filter type Filterer = [Filter] -- | 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. data Filter Filter :: String -> Int -> Filter [$sel:name:Filter] :: Filter -> String [$sel:nlen:Filter] :: Filter -> Int -- | 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. data LogRecord LogRecord :: Logger -> Level -> String -> String -> String -> String -> Int -> ZonedTime -> LogRecord [$sel:logger:LogRecord] :: LogRecord -> Logger [$sel:level:LogRecord] :: LogRecord -> Level [$sel:message:LogRecord] :: LogRecord -> String [$sel:filename:LogRecord] :: LogRecord -> String [$sel:packagename:LogRecord] :: LogRecord -> String [$sel:modulename:LogRecord] :: LogRecord -> String [$sel:lineno:LogRecord] :: LogRecord -> Int [$sel:created:LogRecord] :: LogRecord -> ZonedTime -- | Level also known as severity, a higher Level means a -- bigger Int. newtype Level Level :: Int -> Level -- | Logger is just a name. type Logger = String