/
logging.cr
50 lines (45 loc) · 1.31 KB
/
logging.cr
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
48
49
50
module MStrap
module DSL
module Logging
# Logs a message, without appending a newline.
def log(msg)
return logn(msg) if MStrap.debug?
print msg
Log.info { msg }
end
# Logs a message, appending a newline.
def logn(msg)
puts msg
Log.info { msg }
end
# Logs a success message at the INFO level. On a TTY, this will output in
# green.
def success(msg)
puts msg.colorize(:green)
Log.info { msg }
end
# Log a message at the DEBUG level. This will only be logged when `mstrap`
# is in debug mode.
def logd(msg)
Log.debug { msg }
end
# Logs a message at the WARN level. On a TTY, this will output in yellow.
def logw(msg)
puts "! #{msg}".colorize(:yellow)
Log.warn { msg }
end
# Logs a message at the FATAL level and terminate program. On a TTY, this
# will output in red. In debug, this will also print the stacktrace.
def logc(msg)
Log.fatal { msg }
if MStrap.debug?
abort msg.colorize(:red)
else
puts "!!! #{msg}".colorize(:red)
puts "!!! Check #{MStrap::Paths::LOG_FILE} and/or run with --debug for more detail.".colorize(:red)
exit 1
end
end
end
end
end