-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.hs
39 lines (29 loc) · 1018 Bytes
/
Logging.hs
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
module Logging (red, green, yellow, warn, fatal, err, ice) where
--import GHC.Stack (HasCallStack, withFrozenCallStack)
import System.Exit
import System.IO
red :: String -> String
red s = "\x1b[31m" ++ s ++ "\x1b[0m"
green :: String -> String
green s = "\x1b[32m" ++ s ++ "\x1b[0m"
yellow :: String -> String
yellow s = "\x1b[33m" ++ s ++ "\x1b[0m"
-- green :: String -> String
-- green s = "\x1b[32m" ++ s ++ "\x1b[0m"
-------------------------------
-- Basic logging on IO monad --
-------------------------------
-- ^ Report warning.
warn :: String -> IO ()
warn msg = hPutStrLn stderr $ yellow $ "[WARN] " ++ msg
-- ^ Report error and exit. Unrecoverable.
fatal :: String -> IO a
fatal msg = die $ red $ "[FATAL] " ++ msg
-- ^ Report error.
err :: String -> IO ()
err msg = hPutStrLn stderr $ red $ "[ERROR] " ++ msg
-- ^ Internal compile error.
--ice :: HasCallStack => String -> a
--ice msg = withFrozenCallStack error $ red $ "[ICE] " ++ msg
ice :: String -> a
ice msg = error $ red $ "[ICE] " ++ msg