{- |
   Module     : System.Log.Handler
   Copyright  : Copyright (C) 2004-2011 John Goerzen
   License    : BSD3

   Portability: portable

Definition of log handler support

For some handlers, check out "System.Log.Handler.Simple" and
"System.Log.Handler.Syslog".

Please see "System.Log.Logger" for extensive documentation on the
logging system.

Written by John Goerzen, jgoerzen\@complete.org
-}

module System.Log.Handler(-- * Basic Types
                                LogHandler(..)
                               ) where
import System.Log
import System.Log.Formatter

{- | All log handlers should adhere to this. -}

{- | This is the base class for the various log handlers.  They should
all adhere to this class. -}

class LogHandler a where
                   -- | Sets the log level.  'handle' will drop
                   -- items beneath this level.
                   setLevel :: a -> Priority -> a
                   -- | Gets the current level.
                   getLevel :: a -> Priority
                   -- | Set a log formatter to customize the log format for this Handler
                   setFormatter :: a -> LogFormatter a -> a
                   getFormatter :: a -> LogFormatter a
                   getFormatter a
_ = LogFormatter a
forall a. LogFormatter a
nullFormatter
                   -- | Logs an event if it meets the requirements
                   -- given by the most recent call to 'setLevel'.
                   handle :: a -> LogRecord -> String-> IO ()

                   handle a
h (Priority
pri, String
msg) String
logname =
                       if Priority
pri Priority -> Priority -> Bool
forall a. Ord a => a -> a -> Bool
>= (a -> Priority
forall a. LogHandler a => a -> Priority
getLevel a
h)
                          then do String
formattedMsg <- (a -> LogFormatter a
forall a. LogHandler a => a -> LogFormatter a
getFormatter a
h) a
h (Priority
pri,String
msg) String
logname
                                  a -> LogRecord -> String -> IO ()
forall a. LogHandler a => a -> LogRecord -> String -> IO ()
emit a
h (Priority
pri, String
formattedMsg) String
logname
                          else () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                   -- | Forces an event to be logged regardless of
                   -- the configured level.
                   emit :: a -> LogRecord -> String -> IO ()
                   -- | Closes the logging system, causing it to close
                   -- any open files, etc.
                   close :: a -> IO ()