adding verbose logging level

This commit is contained in:
nek0 2017-12-22 06:28:58 +01:00
parent ea90f8f9cd
commit 09f9ac07ae
3 changed files with 22 additions and 8 deletions

View file

@ -30,6 +30,11 @@ source-repository head
type: git
location: https://github.com/nek0/affection
flag verbse
description: Enable verbose debug messages
default: False
manual: True
flag debug
description: Enable debug messages
default: False
@ -50,6 +55,8 @@ flag examples
default: False
library
if flag(verbose)
cpp-options: -DVERBOSE
if flag(debug)
cpp-options: -DDEBUG
if flag(warn)

View file

@ -4,30 +4,37 @@ module Affection.Logging where
import Debug.Trace
data LogLevel
= Debug
= Verbose
| Debug
| Warn
| Error
log :: LogLevel -> String -> a -> a
#if defined(DEBUG)
#if defined(VERBOSE)
log Verbose s = trace ("VERBOSE: " ++ s)
#endif
#if defined(DEBUG) || defined(VERBOSE)
log Debug s = trace ("DEBUG: " ++ s)
#endif
#if defined(WARN) || defined(DEBUG)
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
log Warn s = trace ("WARN: " ++ s)
#endif
#if defined(ERROR) || defined(WARN) || defined(DEBUG)
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
log Error s = trace ("ERROR: " ++ s)
#endif
log _ _ = id
logIO :: LogLevel -> String -> IO ()
#if defined(DEBUG)
#if defined(VERBOSE)
logIO Verbose s = traceIO ("VERBOSE: " ++ s)
#endif
#if defined(DEBUG) || defined(VERBOSE)
logIO Debug s = traceIO ("DEBUG: " ++ s)
#endif
#if defined(WARN) || defined(DEBUG)
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
logIO Warn s = traceIO ("WARN: " ++ s)
#endif
#if defined(ERROR) || defined(WARN) || defined(DEBUG)
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
logIO Error s = traceIO ("ERROR: " ++ s)
#endif
logIO _ _ = return ()

View file

@ -55,7 +55,7 @@ class (Message msg, Show msg) => Participant prt msg us where
-- ^ The 'Message' to emit
-> Affection us ()
partEmit p m = do
liftIO $ logIO Debug $ "Emitting message: " ++ show m
liftIO $ logIO Verbose $ "Emitting message: " ++ show m
l <- partSubscribers p
mapM_ ($ m) l