-
Notifications
You must be signed in to change notification settings - Fork 0
/
log
executable file
·70 lines (65 loc) · 1.79 KB
/
log
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby -w
require 'ansi'
require 'logger'
# def expensive_error_report
# sleep 3 # Heavy Computation Simulation (patent pending)
# "YOU BROKE IT!"
# end
#
# log = Logger.new(STDOUT)
# log.level = Logger::INFO # set out output level above the DEBUG default
#
# log.debug("We're not in the verbose debug mode.")
# log.info("We do see informative logs though.")
# if log.error? # check that this will be printed, before waste time
# log.error(expensive_error_report)
# end
#
# def expensive_error_report
# sleep 3
# "YOU BROKE IT!"
# end
#
# log = Logger.new(STDOUT)
# log.level = Logger::INFO
# log.datetime_format = "%Y-%m-%d %H:%M " # simplify time output
#
# log.debug("We're not in the verbose debug mode.")
# log.info("We do see informative logs though.")
# if log.error?
# log.error(expensive_error_report)
# end
# Build a Logger::Formatter subclass.
class PrettyErrors < Logger::Formatter
# Provide a call() method that returns the formatted message.
def call(severity, time, program_name, message)
if severity == "ERROR"
print_message = ANSI.color(:black, :bold => true) {": "}
print_message << ANSI.color(:red, :bold => true) {
"#{message}"
}
[border, print_message, border].join("\n") + "\n"
else
super
end
end
def border(n=1)
"-" * n
end
end
# def expensive_error_report(run=true)
# if run
# "unicorn poopsicles"
# else
# "nobody is home"
# end
# end
log = Logger.new(STDOUT)
#log.level = Logger::INFO
log.formatter = PrettyErrors.new # Install custom formatter!
log.debug("We're not in the verbose debug mode.")
log.info("We do see informative logs though.")
log.error("do i get this magic?.")
#if log.error?
# log.error {expensive_error_report(false)}
#end