pituicat/src/Affection/Logging.hs

53 lines
1.5 KiB
Haskell
Raw Normal View History

2017-12-12 12:10:00 +00:00
{-# LANGUAGE CPP #-}
module Affection.Logging where
2018-09-25 05:02:33 +00:00
-- ^ This module defines the logging capability of Affection, whis is derived
-- from "Debug.Trace".
2017-12-12 12:10:00 +00:00
import Debug.Trace
2018-09-25 05:02:33 +00:00
-- | The log level definition
2017-12-12 12:10:00 +00:00
data LogLevel
2018-09-25 05:02:33 +00:00
= Verbose -- ^ Log everything
| Debug -- ^ Log Debug messages and above
| Warn -- ^ Log only Warnings and errors
| Error -- ^ Log only errors
2017-12-12 12:10:00 +00:00
2018-09-25 05:02:33 +00:00
-- | Pure logging function
log
:: LogLevel -- ^ Log level to log to
-> String -- ^ The message string
-> a -- ^ Arbitrary datatype to return
-> a -- ^ Returned data
2017-12-22 05:28:58 +00:00
#if defined(VERBOSE)
log Verbose s = trace ("VERBOSE: " ++ s)
#endif
#if defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
log Debug s = trace ("DEBUG: " ++ s)
#endif
2017-12-22 05:28:58 +00:00
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
log Warn s = trace ("WARN: " ++ s)
#endif
2017-12-22 05:28:58 +00:00
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
log Error s = trace ("ERROR: " ++ s)
#endif
log _ _ = id
2018-09-25 05:02:33 +00:00
-- | Manadic logging function residing in the 'IO' Monad
logIO
:: LogLevel -- ^ Log level to log to
-> String -- ^ The message string
-> IO ()
2017-12-22 05:28:58 +00:00
#if defined(VERBOSE)
logIO Verbose s = traceIO ("VERBOSE: " ++ s)
#endif
#if defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
logIO Debug s = traceIO ("DEBUG: " ++ s)
#endif
2017-12-22 05:28:58 +00:00
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
logIO Warn s = traceIO ("WARN: " ++ s)
#endif
2017-12-22 05:28:58 +00:00
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
2017-12-12 12:10:00 +00:00
logIO Error s = traceIO ("ERROR: " ++ s)
#endif
logIO _ _ = return ()