From 09f9ac07aececfa9f5f25b4ca54362e16b906b7f Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 22 Dec 2017 06:28:58 +0100 Subject: [PATCH] adding verbose logging level --- affection.cabal | 7 +++++++ src/Affection/Logging.hs | 21 ++++++++++++++------- src/Affection/MessageBus/Class.hs | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/affection.cabal b/affection.cabal index 888305d..2257745 100644 --- a/affection.cabal +++ b/affection.cabal @@ -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) diff --git a/src/Affection/Logging.hs b/src/Affection/Logging.hs index 0cf3032..b450774 100644 --- a/src/Affection/Logging.hs +++ b/src/Affection/Logging.hs @@ -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 () diff --git a/src/Affection/MessageBus/Class.hs b/src/Affection/MessageBus/Class.hs index df2b958..66e1815 100644 --- a/src/Affection/MessageBus/Class.hs +++ b/src/Affection/MessageBus/Class.hs @@ -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