-- 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 -- |
-- {-# 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.
--
-- -- 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: -- --