#if MIN_VERSION_base(4,8,1)
#define HAS_SOURCE_LOCATIONS
#endif
module System.Logging.Facade (
log
, trace
, debug
, info
, warn
, error
, Logging
, LogLevel(..)
) where
import Prelude hiding (log, error)
import System.Logging.Facade.Types
import System.Logging.Facade.Class
#ifdef HAS_SOURCE_LOCATIONS
#if ! MIN_VERSION_base(4,9,0)
import GHC.SrcLoc
#endif
import GHC.Stack
#define with_loc (?loc :: CallStack) =>
#else
#define with_loc
#endif
log :: with_loc Logging m => LogLevel -> String -> m ()
log level message = consumeLogRecord (LogRecord level location message)
where
location :: Maybe Location
#ifdef HAS_SOURCE_LOCATIONS
location = case reverse (getCallStack ?loc) of
(_, loc) : _ -> Just $ Location (srcLocPackage loc) (srcLocModule loc) (srcLocFile loc) (srcLocStartLine loc) (srcLocStartCol loc)
_ -> Nothing
#else
location = Nothing
#endif
trace :: with_loc Logging m => String -> m ()
trace = log TRACE
debug :: with_loc Logging m => String -> m ()
debug = log DEBUG
info :: with_loc Logging m => String -> m ()
info = log INFO
warn :: with_loc Logging m => String -> m ()
warn = log WARN
error :: with_loc Logging m => String -> m ()
error = log ERROR