logging module
This commit is contained in:
parent
c33aa67c3e
commit
c82325a1bd
2 changed files with 55 additions and 0 deletions
|
@ -30,12 +30,34 @@ source-repository head
|
|||
type: git
|
||||
location: https://github.com/nek0/affection
|
||||
|
||||
flag debug
|
||||
description: Enable debug messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag warn
|
||||
description: Enable warning messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag error
|
||||
description: Enable error messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag examples
|
||||
description: Build example programs
|
||||
default: False
|
||||
|
||||
library
|
||||
if flag(debug)
|
||||
cpp-options: -DDEBUG
|
||||
if flag(warn)
|
||||
cpp-options: -DWARN
|
||||
if flag(error)
|
||||
cpp-options: -DERROR
|
||||
exposed-modules: Affection
|
||||
, Affection.Logging
|
||||
, Affection.Types
|
||||
, Affection.StateMachine
|
||||
, Affection.MouseInteractable
|
||||
|
|
33
src/Affection/Logging.hs
Normal file
33
src/Affection/Logging.hs
Normal file
|
@ -0,0 +1,33 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
module Affection.Logging where
|
||||
|
||||
import Debug.Trace
|
||||
|
||||
data LogLevel
|
||||
= Debug
|
||||
| Warn
|
||||
| Error
|
||||
|
||||
log :: LogLevel -> String -> a -> a
|
||||
#if defined(DEBUG)
|
||||
log Debug s = trace ("DEBUG: " ++ s)
|
||||
#endif
|
||||
#if defined(WARN) || defined(DEBUG)
|
||||
log Warn s = trace ("WARN: " ++ s)
|
||||
#endif
|
||||
#if defined(ERROR) || defined(WARN) || defined(DEBUG)
|
||||
log Error s = trace ("ERROR: " ++ s)
|
||||
#endif
|
||||
log _ _ = id
|
||||
|
||||
logIO :: LogLevel -> String -> IO ()
|
||||
#if defined(DEBUG)
|
||||
logIO Debug s = traceIO ("DEBUG: " ++ s)
|
||||
#endif
|
||||
#if defined(WARN) || defined(DEBUG)
|
||||
logIO Warn s = traceIO ("WARN: " ++ s)
|
||||
#endif
|
||||
#if defined(ERROR) || defined(WARN) || defined(DEBUG)
|
||||
logIO Error s = traceIO ("ERROR: " ++ s)
|
||||
#endif
|
||||
logIO _ _ = return ()
|
Loading…
Reference in a new issue