1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--------------------------------------------------------------------------
--- This module provides operation for log messages and setting
--- the log level for the analyses.
---
--- @author Michael Hanus
--- @version March 2017
--------------------------------------------------------------------------

module Analysis.Logging
 ( getDebugLevel, setDebugLevel, debugMessage, debugString
 ) where

import Global

--------------------------------------------------------------------------
--- Global variable to store the debug level.
--- Debug levels:
--- 0 : show nothing
--- 1 : show worker activity, e.g., timings
--- 2 : show server communication
--- 3 : ...and show read/store information
--- 4 : ...show also stored/computed analysis data
debugLevel :: Global Int
debugLevel = global 1 Temporary

--- Gets the current debug level.
getDebugLevel :: IO Int
getDebugLevel = readGlobal debugLevel

--- Sets the debug level to a new value.
setDebugLevel :: Int -> IO ()
setDebugLevel l = writeGlobal debugLevel l

--------------------------------------------------------------------------

--- Prints a message line if debugging level is at least n:
debugMessage :: Int -> String -> IO ()
debugMessage n message = debugString n (message++"\n")

--- Prints a string if debugging level (as specified in the Config file)
--- is at least n:
debugString :: Int -> String -> IO ()
debugString n message = do
  dl <- getDebugLevel
  when (dl>=n) $ putStr message

--------------------------------------------------------------------------