forked from nestorInc/jukebox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.rb
More file actions
38 lines (30 loc) · 870 Bytes
/
display.rb
File metadata and controls
38 lines (30 loc) · 870 Bytes
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
SAVE_LAST_EVENT = 20;
$events = [];
def print_color(prefix, color = 2, str, file)
line = "[#{Time.now()}] [\033[#{30+color}m#{prefix}\033[0m] #{str}";
puts(line);
file.puts(line) if(file);
end
def display(prefix, color, str, file, print = true)
print = true if(ENV["IS_DEBUG"] != nil)
print_color(prefix, color, str, file) if(print == true);
$events.push([Time.now(), str]);
$events = $events.last(SAVE_LAST_EVENT);
end
def log(str, print = true, file = nil)
display("info", 2, str, file, print);
end
def warning(str, print = true, file = nil)
display("warning", 3, str, file, print);
end
def error(str, print = true, file = nil)
display("error", 1, str, file, print);
end
def debug(str, file = nil)
display("debug", 2, str, file, false);
end
def dump_events()
$events.reverse.map { |time, str|
"#{time} #{str}"
}.join("\n");
end